Space Python Loading Python…

Type Conversion

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Readings that won't add

Fix the codeEasy 3 stages

Two sensor readings add up to 12080 instead of 200 because they arrived as text. Predict it, find out why and fix it with int(), then add decimal readings with float().

Start the challenge

Status message crash

Fix the codeEasy 3 stages

A status line crashes with a TypeError because it joins text and a number with +. Predict it, read the error, fix it with str(), then build a docking status line.

Start the challenge

Round or cut?

Write the codeMedium 3 stages

int() cuts the decimals off, round() rounds, and round(2.5) gives 2. Predict the difference, investigate Python's rounding rule, then round a fuel reading two ways.

Start the challenge

Fuel for a burn

Write the codeEasy 2 stages

Ask for an engine burn length with input(), turn it into a number with float() and work out the propellant it uses, then read the tank level too and show what the burn leaves.

Start the challenge

input() returns text

Fix the codeEasy 3 stages

A crew count read with input() crashes when 1 is added to it. Predict the crash, find out what input() really returns, fix it with int(), then write a packing tool that reads two numbers.

Start the challenge

Discussion

Stuck on this example or want to go further? Ask here, or see what others asked.

Log in to ask and reply.

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:].