Editor

Python compiler with input()

When your program calls input(), the console waits for your answer, like a terminal.

A program that asks two questions

name = input("What is your name? ")
age = int(input("How old are you? "))

print(f"Hello {name}, next year you will be {age + 1}.")

# A loop that keeps asking until the answer is right
secret = 7
guess = int(input("Guess a number from 1 to 10: "))
while guess != secret:
    hint = "higher" if guess < secret else "lower"
    guess = int(input(f"Try {hint}: "))
print("You got it!")

Open this in the editor and press Run.

How it works

  1. Press Run (or Ctrl+Enter). The question appears in the console and the program pauses.
  2. Type your answer in the console and press Enter.
  3. Each later input() asks again, so loops, menus and games work as they do on your computer.

Questions

Does this online Python compiler support input()?

Yes. The console waits for each answer, as many times as your program asks, including inside loops.

Do I need to give all the input before running?

No. You answer each question when the program asks it, so the next question can depend on your last answer. There is no separate stdin box to fill in.

How do I read a number with input()?

input() returns a string, so convert it: age = int(input("Age? ")) for whole numbers, or price = float(input("Price? ")) for decimals. If the answer is not a number, int() raises a ValueError.

Where does input() work?

In the editor on Chromebooks, Windows, Mac, Linux and Android, in Chrome, Edge and Firefox. Not on iPhone and iPad, where browsers do not yet let a page pause for input, and not in code boxes embedded on other websites.

More: the editor · Python turtle · exercises · programs with output