Code

Lantern Calculator

Let's combine everything into a tiny calculator. The trick is to convert input right away:

boxes = int(input("How many boxes? "))
price = float(input("Price per box? "))
print("Total:", boxes * price)

Read the first line from the inside out: input(...) gets the text, int(...) turns it into a number, then = stores it.

Use int() for things you count (lanterns, people) and float() for things that can have decimals (litres, prices).

Assignment

The Input box has two lines: 12 and 3.

  1. Ask Lanterns on the island? and store it as an int in lanterns.
  2. Ask Hours each lantern burns? and store it as an int in hours.
  3. Set total_hours to lanterns times hours.
  4. Print Total lantern-hours: and the number, using a comma.

Expected output:

Lanterns on the island? 12
Hours each lantern burns? 3
Total lantern-hours: 36