lives = 3Line-by-line explanation
livesis the variable name.=stores a value.3is an integer because it is whole.
temperature = 21.5Line-by-line explanation
temperaturenames the value.=stores it.21.5is a float because it has a decimal point.
Numbers are written without quote marks. Quotes would create text that only looks like a number.
print(3 + 2)Line-by-line explanation
3and2are integers.+asks Python to add them.printdisplays the result5.
Computers store many decimal values as close approximations. You will learn the practical effect of that later; for now, use floats for ordinary measurements.
Tiny Practice: Store Two Numbers
Store an age as an integer and a height in metres as a float.
Starter template
age = 0
height = 0.0Line-by-line explanation
- The first line needs a whole number.
- The second line needs a decimal number.
Hint
- Do not use quotes.
- Age normally has no decimal point.
- Metres normally use a decimal point.
Show Solution
age = 12
height = 1.55Line-by-line explanation
12is an integer.1.55is a float.- Your values may be different.