Space Python Loading Python…

What arrived?

Write the codeEasy 3 stages

Packets from the engine sensors don't always arrive in the shape you'd expect. Some numbers come as real numbers, some as text that only looks like a number, and one value says "False" in quotes. Before the flight computer can calculate anything, it has to know what it actually got.

type() tells you. Predict what it shows, investigate a whole packet, then convert one yourself.

Don't run the code yet. Read it and decide what it will print on its first line. 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.

type() prints a value's type as <class '...'>. Writing just the type name in your prediction is fine.

Predict, then run
Leave the program as it is

Finish stage 1 to unlock this stage.

Investigate. Find out what type float(temperature) gives and store it in converted_type. Then find out what bool(valve_open) gives, True or False, and store it in bool_of_valve. Run them to check, then remove any lines you added before you check.

Modify. Print the type of every value in the packet, one line each, following the pattern of the first two lines:

sensor_id: <class 'str'>
temperature: <class 'str'>
pressure: <class 'float'>
valve_open: <class 'str'>
sample_count: <class 'int'>
Investigate two conversions
Print every type in the packet

Finish stage 2 to unlock this stage.

Everything in this packet from the navigation computer arrived as text. Convert each value to the type it should have, into the new variables named in the comments, then print each new value and its type:

altitude_km: 408 <class 'int'>
speed_kms: 7.66 <class 'float'>
crew: 3 <class 'int'>
Convert and print
Keep what arrived
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

Basic Data Types

basic-data-types.py
# Basic data types in Python

# int - whole numbers
number_of_planets = 8
print("Planets:", number_of_planets, type(number_of_planets))

# float - decimal numbers
deep_space_temp = -270.45
print("Temperature:", deep_space_temp, type(deep_space_temp))

# str - text (string)
galaxy = "Milky Way"
print("Galaxy:", galaxy, type(galaxy))

# bool - logical value
is_life_on_mars = False
print("Life on Mars:", is_life_on_mars, type(is_life_on_mars))
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:].