Space Python Loading Python…

Packing crates

Write the codeMedium 2 stages

The lander's drill has filled its sample tubes, and they fly home in padded crates with 12 slots each. The loading crew needs a packing list: how many crates, and how full the last one is.

Start with the crates the tubes fill completely, then work out the full packing list.

Work out how many crates the 100 tubes fill completely, and how many tubes are left over:

Full crates: 8
Tubes left over: 4

// counts how many times 12 fits into 100, and % gives what's left.

Count the full crates
Calculate from the variables

Finish stage 1 to unlock this stage.

The tubes left over still need a crate, so the packing list needs the total. Replace the two lines with:

Crates needed: 9
Tubes in the last crate: 4
Empty slots: 8

Rounding a division up is a classic trick: (tubes + slots_per_crate - 1) // slots_per_crate. Adding one tube less than a full crate pushes any leftover tubes into one more crate, but never adds a crate when they fit exactly.

Test your idea on the awkward case: 96 tubes fill exactly 8 crates, so the last crate holds 12 tubes, not 0.

Print the packing list
Handle tubes that fit exactly
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

Floor Division and Modulo

floor-division-modulo.py
# Floor division (//) and modulo (%)

# ISS completes one orbit every 92 minutes
# How many full orbits in 24 hours?
minutes_in_day = 24 * 60
orbit_period = 92

full_orbits = minutes_in_day // orbit_period
remaining = minutes_in_day % orbit_period

print("Full ISS orbits per day:", full_orbits)
print("Minutes into next orbit:", remaining)

# Mars signal delay: 1,124 seconds
# Break into minutes and seconds
signal_delay = 1124
minutes = signal_delay // 60
seconds = signal_delay % 60
print(f"\nMars signal delay: {minutes} min {seconds} sec")

# Distribute 50 rations among 6 crew members
rations = 50
crew = 6
per_person = rations // crew
extras = rations % crew
print(f"\nRations per astronaut: {per_person}")
print(f"Extra rations: {extras}")

# Check if a mission number is even or odd
mission = 42
if mission % 2 == 0:
    print(f"\nMission {mission} is even")
else:
    print(f"\nMission {mission} is odd")
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:].