Skip to content

Practical exercise

Build a fuel cost calculator for a Lahore commute

Variables are little labelled boxes for numbers. The petrol pump charges by litre. Your motorbike eats litres by the kilometre. Today you will use four variables to find out exactly what your daily commute costs in rupees, and notice how changing one input changes the answer.

30 min·practitioner
Mimi the mascot, encouraging you

Now try it

Build a fuel cost calculator for a Lahore commute

Stretch

Add a loop that prints the cost for distances 10, 20, 30, 40, 50, 60 km. Use a for loop: for d in range(10, 70, 10):. Take screenshot of full output table.

Goes into your portfolio

Two screenshots of your Python program at 30 km and 60 km commute showing different rupee outputs, plus a one line conclusion sentence on paper or in the comments.