Space Python Loading Python…

Wrong average

Fix the codeEasy 3 stages

Three sensors measure the temperature of Python One's hull, and the thermal control system watches their average. Today the average says 47 °C, while every single sensor reads around 21 °C.

Predict what the code prints, find out where the maths goes wrong, fix it, then work out an average that has a trap of its own.

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.

Three readings, one average. Work out what Python will print, line by line.

Predict, then run
Leave the program as it is

Finish stage 1 to unlock this stage.

Investigate. Store the name of the reading Python divides by 3 in divided_by_3, as text. Then work out what 2 + 4 / 2 gives and store it in two_plus_four_halved. Run it to check, and remove any line you added before you check.

Modify. Fix the calculation so it averages all three readings: add them up first, then divide. It must print:

Average hull temperature: 20.9 °C
Find what goes first
Average all three readings

Finish stage 2 to unlock this stage.

The rover drove two legs: 6.0 km in 0.75 hours, then 1.5 km in half an hour. Its average speed for the whole drive is the total distance divided by the total time:

Average speed: 6.0 km/h

Careful: it isn't the average of the two legs' speeds. The rover spent longer on the first leg, so that leg counts for more.

Print the average speed
Works for any drive
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

Order of Operations

order-of-operations.py
# Order of operations in Python: PEMDAS
# Parentheses, Exponents, Multiplication/Division, Addition/Subtraction

# Python follows PEMDAS automatically
result = 2 + 3 * 4
print("2 + 3 * 4 =", result)

# Parentheses override the default order
result = (2 + 3) * 4
print("(2 + 3) * 4 =", result)

# Exponents beat multiplication
energy = 2 * 3 ** 2
print("2 * 3 ** 2 =", energy)

# Astrophage fuel from Project Hail Mary
# Einstein's E = m * c^2
mass = 0.001
c = 3e8
energy = mass * c ** 2
print(f"Energy from 1 gram: {energy:.2e} J")

# Average speed - WRONG without parentheses
# Voyager 1 covered two distances at different times
distance1 = 150
distance2 = 270
time1 = 2
time2 = 3
wrong_avg = distance1 + distance2 / time1 + time2
print(f"Wrong average: {wrong_avg} km/h")

# CORRECT with parentheses
correct_avg = (distance1 + distance2) / (time1 + time2)
print(f"Correct average: {correct_avg} km/h")

# Escape velocity from Earth
# v = sqrt(2 * G * M / r)
G = 6.674e-11
M_earth = 5.972e24
r_earth = 6.371e6
v_escape = (2 * G * M_earth / r_earth) ** 0.5
print(f"Escape velocity: {v_escape:.0f} m/s")
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:].