LightMySky

Input, Output and Type Conversion

Reading what a user types, printing results back, and converting typed text into a number before doing arithmetic with it.

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • Read a value from the user and store it in a variable
  • Convert typed input to a whole number or a decimal before calculating with it
  • Explain why adding two typed numbers without converting them joins them as text

1 · Read

Your program can ask the user to type something with input(), and show things back with print(). Whatever is typed always arrives as text, even when it looks like a number. You store it in a variable so you can use it later.

Try it together

A shop program needs a quantity and a price. It runs quantity = int(input()) and price = float(input()), then total = quantity * price, then print(total). With 3 and 5.0 typed in, it prints 15.0.

Use int() to turn typed text into a whole number, and float() for a decimal like a price. Mixing a whole number with a decimal gives a decimal, and dividing with / always gives a decimal too.

Good to know

Never skip the conversion step. Adding two typed values without converting glues them as text, so 3 and 5 become 35 instead of 8.

Read text with input(), convert with int() or float(), then calculate and print.

2 · Watch

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Then practise

8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Spotted a problem on this page? Tell us
Input, Output and Type Conversion · Computing, ages 14 to 15 · LightMySky