Space Python Loading Python…

Float surprise

Write the codeEasy 3 stages

Two small top-ups of fuel, 0.1 and 0.2 tonnes, go into the tank. Adding them up should be the easiest calculation on board, and yet Python prints something nobody expects.

Predict it, look closely at what came out, then make the display show what a pilot needs to see.

Don't run the code yet. Read it and decide what it will print. Write your guess in prediction, at the top, between the quotes. Then run it and compare.

Any guess passes this stage: the point is to think before you run. After you check, you'll see your prediction next to what Python printed.

It's 0.1 plus 0.2. Write exactly what you expect Python to print.

Predict, then run
Leave the program as it is

Finish stage 1 to unlock this stage.

Investigate. Count how many digits Python prints after the decimal point for total and store the number in digits_after_point.

Modify. Keep the raw value, and under it add the line the fuel display shows, rounded to two decimal places:

0.30000000000000004
Fuel: 0.30 t
Count the digits
Add the display line

Finish stage 2 to unlock this stage.

Two engine burns last 1.1 and 2.2 seconds. Add them up, print the raw total, then the value the display shows with one decimal place:

Raw total: 3.3000000000000003
Burn time: 3.3 s
Print the raw total and the display value
Calculate, don't type
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

Basic Data Types

basic-data-types.py
# Basic data types in Python

# int - whole numbers
number_of_planets = 8
print("Planets:", number_of_planets, type(number_of_planets))

# float - decimal numbers
deep_space_temp = -270.45
print("Temperature:", deep_space_temp, type(deep_space_temp))

# str - text (string)
galaxy = "Milky Way"
print("Galaxy:", galaxy, type(galaxy))

# bool - logical value
is_life_on_mars = False
print("Life on Mars:", is_life_on_mars, type(is_life_on_mars))
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].