Space Python Loading Python…

Landing site

Write the codeEasy 2 stages

NASA's Perseverance rover landed in Jezero crater on Mars in February 2021. Mission planners store every site as a pair of numbers, latitude and longitude, that always belong together and in that order.

Keep the pair in a tuple, unpack it, then print it the way maps and mission documents write coordinates.

Unpack the tuple into two variables, lat and lon, in one line, then print both with four decimal places:

Latitude: 18.4447
Longitude: 77.4508

a, b = pair puts the first value in a and the second in b. :.4f shows four decimal places.

Unpack and print
Works for any site

Finish stage 1 to unlock this stage.

Maps don't write negative coordinates: they write the number without its sign and a letter, N or S for latitude and E or W for longitude. Add a line in that form:

Latitude: 18.4447
Longitude: 77.4508
Site: 18.4447° N, 77.4508° E

Choose each letter with an if: 0 and above is N or E, below 0 is S or W. abs() gives a number without its sign. Curiosity's landing site, (-4.5895, 137.4417), would be 4.5895° S, 137.4417° E.

Write it the map way
Right in every hemisphere
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

Tuple Unpacking

tuple-unpacking.py
# Tuple unpacking: one line, many variables

# New Horizons flyby of Pluto, 14 July 2015
flyby = ("New Horizons", "Pluto", 12472)
probe, target, closest_km = flyby
print(f"{probe} passed {target} at {closest_km} km")

# Asterisk grabs everything that is left over
ares3 = ("Lewis", "Johanssen", "Martinez", "Vogel", "Beck", "Watney")
commander, *crew, botanist = ares3
print("Commander:", commander)
print("Crew:", crew)
print("Left behind on Mars:", botanist)

# Swapping two values without a temporary variable
primary_dish, backup_dish = "Goldstone", "Canberra"
primary_dish, backup_dish = backup_dish, primary_dish
print(f"Now transmitting from {primary_dish}, backup is {backup_dish}")

# Underscore marks a value you do not need
sample = ("Ryugu", 2020, 5.4)
asteroid, _, grams = sample
print(f"Hayabusa2 returned {grams} grams of {asteroid}")

# Unpacking inside a for loop
moons = [("Titan", 5150), ("Enceladus", 504), ("Iapetus", 1469)]
for name, diameter_km in moons:
    print(f"{name}: {diameter_km} km across")
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:].