Space Python Loading Python…

Readings summary

Write the codeEasy 2 stages

After every pass over the ground station, the engine team gets a summary of the temperature readings: the lowest, the highest and the average. Nobody reads five hundred numbers; everybody reads the summary.

Summarise the readings with Python's built-in functions, then make sure the summary survives a pass with no readings at all.

Print the lowest and the highest reading, and the mean with one decimal place:

Min: 398.0
Max: 455.2
Mean: 419.5

min() and max() take the whole list. The mean is the sum of the readings divided by how many there are.

Summarise the readings
Works for any readings

Finish stage 1 to unlock this stage.

Add the spread, the highest reading minus the lowest, with one decimal place. Then guard against a pass with no readings: an empty list would crash min() and the division. For an empty list, print only No readings.

Min: 398.0
Max: 455.2
Mean: 419.5
Spread: 57.2

Check len(readings) == 0 first, and move the summary under else.

Add the spread
Survive an empty pass
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 Lists

creating-lists-python.py
# Lists - ordered collections of items

# Square brackets, items separated by commas
planets = ["Mercury", "Venus", "Earth", "Mars"]
print("Inner planets:", planets)

# One list can hold different types at once
mission = ["Hail Mary", 3, True, 11.9]
print("Mission record:", mission)

# An empty list is still a list, ready to be filled later
sample_tubes = []
print("Samples collected:", sample_tubes)

# len() counts the items
crew = ["Grace", "Yao", "Ilyukhina"]
print("Crew size:", len(crew))
print("Tubes filled:", len(sample_tubes))

# The in operator checks membership
candidate_stars = ["Tau Ceti", "Epsilon Eridani", "Wolf 359", "Sirius"]
print("Stars checked:", len(candidate_stars))

if "Tau Ceti" in candidate_stars:
    print("Tau Ceti is on the target list")

if "Betelgeuse" not in candidate_stars:
    print("Betelgeuse is too far to bother")
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:].