Space Python Loading Python…

Running totals

Write the codeEasy 3 stages

A variable doesn't have to keep the value you first gave it. During a mission the fuel level changes with every burn and every top-up, and the flight computer keeps one variable up to date instead of creating a new one for each step.

Predict how -= and += change a value, follow the fuel through a whole sequence, then track a battery yourself.

Don't run the code yet. Read it and decide what it will print on its last line. 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.

Follow fuel_kg line by line: it starts at 5000 and changes twice.

Predict, then run
Leave the program as it is

Finish stage 1 to unlock this stage.

Investigate. Work out what fuel_kg holds right after fuel_kg -= burn_1 and store the number in after_first_burn.

Modify. Continue the sequence: the second burn, the top-up and the third burn, each with -= or +=, printing the level after each step:

After burn 1: 3800 kg
After burn 2: 3150 kg
After top-up: 3550 kg
After burn 3: 2700 kg
Follow the first burn
Track the whole sequence

Finish stage 2 to unlock this stage.

The battery starts full at 100%. During one orbit the comms pass uses 12.5%, the heaters 20.2%, and then solar charging adds 30%. Track it with -= and += and print the level after each step, with one decimal place:

Battery after comms pass: 87.5%
Battery after heaters: 67.3%
Battery after solar charging: 97.3%
Track the battery
Update one variable
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

Creating Variables

creating-variables-python.py
# Variables store data under a name
# Create them by assigning a value with =

ship_name = "Project Hail Mary"
crew_count = 3
fuel_remaining = 78.4
in_deep_space = True

print("Ship:", ship_name)
print("Crew:", crew_count, "people")
print("Fuel remaining:", fuel_remaining, "%")
print("In deep space:", in_deep_space)
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:].