Learn / Python / Variables and maths: millimetres to inches

Python, lesson 2 of 6

Variables and maths: millimetres to inches

A variable is a name for a value, so you can use it again. You make one with =:

width = 40
height = 25
area = width * height
print(area)   # 1000

Python does maths with + - * /. To round a number, use round(number, places), for example round(3.14159, 2) gives 3.14.

Your turn

A bolt is 25 mm long. Keep length_mm = 25, then set length_in to the length in inches (1 inch is 25.4 mm), rounded to 2 decimal places.

Press Run to see what your code prints.