Skip to main content
Mentr by PaprlybyPaprly
Student Guides

Online Python Compiler With input(): How It Works

Why input() breaks in many online Python compilers, the two ways browsers handle it, and how to run quizzes and games that ask questions as they go.

Mentr Engineering7 min read

Beginners' programs are full of input(): quizzes, calculators, number-guessing games. Yet input() is the feature online Python compilers most often get wrong. This article explains why it's hard, the two ways compilers handle it, and what to expect from each.

Why input() is hard in a browser

In a terminal, input() pauses your program until you press Enter. A web page can't pause like that: JavaScript must never block, or the page freezes. So a compiler has to find another way for Python to wait for you.

Way 1: type all answers before you run

Many compilers give you an Input (stdin) box. You write every answer, one per line, then press Run. Each input() call reads the next line.

  • Works everywhere, including older browsers.
  • You must know all the answers in advance, so a guessing game that reacts to your guesses doesn't really work.
  • Prompts and answers appear separately, which confuses beginners.

Way 2: a real interactive console

The better experience is a console where the prompt appears, you type the answer right after it, press Enter, and the program continues, exactly like a terminal.

Mentr's compiler does this by running Python in a Web Worker (a background thread). When Python calls input(), the worker sleeps on a SharedArrayBuffer using Atomics.wait(). When you press Enter, the page writes your line into that shared memory and wakes the worker. Only the background thread waits, so the page stays responsive.

Try a program that needs real input()

Paste this guessing game into the compiler. It only makes sense with an interactive console, because each answer depends on the last hint.

import random
secret = random.randint(1, 20)
while True:
    guess = int(input("Guess (1-20): "))
    if guess == secret:
        print("Got it!")
        break
    print("Higher" if guess < secret else "Lower")
  • Time spent waiting for your answer doesn't count toward the 15-second run limit.
  • Press Ctrl + D on an empty answer to send end-of-input (EOFError), like a terminal.
  • Answers you type are shown in green in the output so you can follow the conversation.

Common questions

Why does input() give EOFError in some online compilers?
The compiler ran out of pre-typed input. In stdin-box compilers, each input() reads one line you entered before running; if there are fewer lines than input() calls, Python raises EOFError.
Does Mentr's online Python compiler support input()?
Yes. On modern browsers you type answers straight into the output as the program runs. On older browsers it shows an Input box where you write one answer per line.
Does waiting for input count toward the time limit?
No. The 15-second limit pauses while the program is waiting for you to type.