Skip to the content

Asking for input

Python · Unit 1: First steps

input() reads what the person types.

It always gives back text (str), even if they type a number.

name = input()
print("Hello,", name)

Prints

Hello, Emma

To do calculations with what they type, convert the text: int(input()) for whole numbers and float(input()) for decimals.

age = int(input())
print(age + 1)

Prints

16

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    If the person types Emma, what does it print?

    name = input()
    print("Hello, " + name + "!")
  2. 2. Multiple choice

    What type is what input() gives back?

  3. 3. Predict the output

    If the person types 5, what does it print?

    number = input()
    print(number * 2)
  4. 4. Put the lines in order

    Order the lines to greet whoever types their name.

  5. 5. Multiple choice

    What does int("8") do?

  6. 6. Complete the code

    The person types 4. Fill in so it prints 12.

    number = ___(input())
    print(number * 3)
  7. 7. Put the lines in order

    The person types 7. Order the lines to print its double.

  8. 8. Find the bug

    This program should add 10 to the number they type. Which line has the error?

    number = input()
    print(number + 10)
  9. 9. Complete the code

    The person types 1.5 (liters of water a day). Fill in to print how many liters that is in 2 days.

    liters = ___(input())
    print(liters * 2)
  10. 10. Predict the output

    The person types 3 and then 4. What does it print?

    a = input()
    b = input()
    print(a + b)
    print(int(a) + int(b))
Do this lesson

It opens in your browser. It is free and you do not need an account to start.

See all lessons →