Decimal comma
The burn calculator works perfectly in the simulator. Then an operator at a European ground station types the burn length the way it is written in Poland and much of Europe, 42,5, and the program stops.
Predict what happens, find out why, make the calculator accept both ways of writing decimals, then read pressure readings written the European way.
Finish stage 1 to unlock this stage.
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.
When you run it, the program asks for the burn length: type 42,5, with a comma, the way it is written in Poland. What will happen?
You don't need to change the code in this stage. The check runs it with 42.5, and shows what 42,5 does next to your prediction.
Finish stage 1 to unlock this stage.
Investigate. Run the program and type 42,5. Find out what answer.replace(",", ".") gives and store it, as text, in replaced. Then find out what answer itself holds after that and store it in answer_after. Remove any lines you added before you check.
Modify. Make the program accept both 42,5 and 42.5. For either, it must print:
Fuel used: 318.8 kg
Finish stage 2 to unlock this stage.
A ground station in Europe sends pressure readings typed like 1 013,25: a space between the thousands and a comma before the decimals. Ask for a reading with input() and print it with two decimal places:
Pressure: 1013.25 hPa
Two replacements: remove the spaces, then turn the comma into a dot. Readings typed with a dot, like 1013.25, must still work.
Hints
Methods find, count, replace and split
# Searching, counting, and splitting strings
# A snippet of mission log text
report = "Mars rover Curiosity landed. Curiosity is still active."
# .find() returns the index of the first match, or -1 if not found
position = report.find("Curiosity")
print("Curiosity first appears at index:", position)
missing = report.find("Voyager")
print("Voyager index:", missing) # -1 means not found
# .count() returns how many times a substring appears
mentions = report.count("Curiosity")
print("Curiosity mentioned:", mentions, "times")
# .replace() can clean up or swap text - here we redact a name
public_report = report.replace("Curiosity", "[REDACTED]")
print(public_report)
# .split() breaks a string into a list, using a separator
crew_data = "Mark Watney,Botanist,Ares III,Sol 18"
fields = crew_data.split(",")
print("Fields:", fields)
# We can grab individual pieces by index
print("Name:", fields[0])
print("Role:", fields[1])
# Splitting on whitespace - no argument needed
sentence = "Houston we have a problem"
words = sentence.split()
print("Words:", words)
Separate arguments with commas. They're passed on every Run as sys.argv[1:].