LESSON 04 / 05

Reading Input

input() asks the user a question and always returns text. Convert it with int() or float() and build interactive programs.

๐ŸŽ“Beginnerlevel
โฑ๏ธ25 minto finish
โœ๏ธ2activities

๐Ÿ“‚ First Steps in Python๐Ÿท๏ธ Python basics

๐ŸŽฏ By the end of this lesson you canโ€ฆ

  • Read input with input()
  • Convert input to numbers
  • Build a small interactive calculator
๐Ÿ Python greet.py ๐Ÿ‘† Tap a line to explain it
1name = input("What's your name? ")2age = int(input("How old are you? "))3print("Hi", name + "!")4print("Next year you'll be", age + 1)
๐Ÿ Python bill-split.py
1bill = float(input())2people = int(input())3share = bill / people4print("Each person pays", round(share, 2))
๐Ÿ’ก Concept check
What is type(input()) when the user types 42?
๐Ÿ› ๏ธ Bill splitter with tip

Read the bill amount and the number of people. Add a 10% tip, then print each personโ€™s share rounded to 2 decimals.

๐Ÿ“Œ Key takeaways

  • input() always returns a string.
  • int(input()) or float(input()) for numbers.
  • In lessons, input() reads the next line of the Inputs box.

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.