Understand how to input strings and numbers into variables

From Computer Science Wiki
Revision as of 09:13, 25 August 2021 by Mr. MacKenty (talk | contribs)
Jump to navigation Jump to search
Python programming language[1]


This page is meant to be used in conjunction with our excellent resource for learning python. This page tracks with objective 2.

Please remember:

  1. Data is input by a user into a variable.
  2. Variables have a data type: string, integer or float as examples, indicating how much memory they will use and the type of data they will store.




Simple adder challenge[edit]

Write a program that asks the user for two numbers. Part of the reason this one can be tricky is because you need to think about the Programming#Primitive data types of data you are using. Please remember in Python we can't mix integers and strings.


Click the expand link to see one possible solution, but NOT before you have tried and failed at least three times

number_1 = int(input("enter first number: "))
number_2 = int(input("enter second number: "))
answer = number_1 + number_2
print("The answer is ", str(answer))

Test marks challenge[edit]

Write a program that will ask the user to enter three test marks out of 100 and output the average. It might helpful to remember an old friend, PEMDAS!


Click the expand link to see one possible solution, but NOT before you have tried and failed at least three times

number_1 = int(input("enter the first test score: "))
number_2 = int(input("enter the second test score: "))
number_3 = int(input("enter the third test score: "))
answer = (number_1 + number_2 + number_3) / 3
print("The average of the three tests scores is: ", str(answer))


Temperature converter challenge Difficulty:  G Write a program to enter a temperature in degrees Fahrenheit and display the equivalent temperature in degrees Centigrade. The formula for conversion is Centigrade = (Fahrenheit – 32) * (5/9) Height & weight challenge Difficulty:  G Write a program to convert a person’s height in inches into centimetres and their weight in stones into kilograms. [1 inch = 2.54 cm and 1 stone = 6.364 kg] Toy cars challenge Difficulty:  G A worker gets paid £9/hour plus £0.60 for every toy car they make in a factory. Write a program that allows the worker to enter the number of hours they have worked and the number of trains they have made. The program should output their wages for the day. Fish tank volume challenge Difficulty:  G Write a program that will ask the user to enter the length, depth and height of a fish tank in cm. Calculate the volume of water required to fill the tank and display this volume in litres and UK gallons. To calculate volume in litres, multiply length by depth by height and divide by 1000.


If you are still stuck, or you have other questions, you may want to ask a question on our discussion board.

References[edit]