- Variables detect what data is in them if you assign them values.
- Note strings are declared within speech marks “”
x = 10
y = 10.4
z = "hello"
- If you input from the keyboard, the computer will always treat input as a string. You can save some time by casting (converting) the data type of variable when you ask for the input
age = int(input("What's your age? "))
height = float(input("What's your height? "))
Tasks
- Use the techniques shown above to create a program that asks for the age and height from the user, adds them together and prints them out to the screen
- Save, print and label your code
Hints
- Remember to use str() to convert back when printing if you are adding strings and numbers. For example:
print("Your age is: " + str(age))
Extension Task
Use these techniques to ask the user several questions (both string and number), and print out a short story using the entered values