Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Tutorial
  3. Reading User Input with Python input()

Getting started · Tutorial 7

Reading User Input with Python input()

Read text and numbers from standard input, understand prompts, and design programs that handle supplied input cleanly.

Open the compilerPractice exercises
beginner7 min readUpdated November 19, 20263 learning goals
On this page
  1. How standard input works in ILoveCompiler
  2. Reading numbers
  3. Reading several values from one line
  4. Reading until empty input
  5. Practice

What you will learn

  • Read a line with input()
  • Convert input to numbers
  • Understand how ILoveCompiler supplies standard input
Before this lesson: Python Type Conversion and Input Values

input() reads one line from standard input and returns it as a string without the trailing newline.

Python
name = input("What is your name? ")
print(f"Hello, {name}!")

The argument is a prompt. It is optional. If you pass a prompt, ILoveCompiler writes it to output before reading the line.

How standard input works in ILoveCompiler#

ILoveCompiler is not a fully interactive terminal. You provide all input lines before the program starts, using the Input panel in the console.

  • One input() call consumes one line.
  • A blank line is a valid input value.
  • If the program asks for more lines than are available, input() raises EOFError.
  • Prompts are echoed only when you supply a non-empty prompt.

This design keeps runs deterministic and makes exercises easy to test.

Reading numbers#

Python
first = int(input("First number: "))
second = int(input("Second number: "))
print(first + second)

With input lines 12 and 30, the output includes the prompts and echoes:

Expected output

First number: 12 Second number: 30 42

If you need clean output for automated tests, call input() without a prompt:

Python
first = int(input())
second = int(input())
print(first + second)

Reading several values from one line#

split() separates a line on whitespace:

Python
width, height = map(int, input("Width and height: ").split())
print(f"Area: {width * height}")

If the user enters 3 4, both values are parsed. If they enter a different number of values, unpacking raises ValueError. Validate the count when that matters.

Reading until empty input#

A common pattern reads lines until an empty one:

Python
lines = []

while True:
    line = input()
    if line == "":
        break
    lines.append(line)

print(f"Collected {len(lines)} lines")

With supplied input, include a blank line at the end to stop the loop.

Provide input before pressing Run

If a program pauses or raises EOFError, check the Input tab. Every input() call needs a matching line.

Practice#

Write a program that reads a name and a favourite number, then prints a sentence using both. Run it once with the prompts included, and once with promptless input() calls to compare the output.

Previous tutorialPython Type Conversion and Input ValuesNext tutorialPython Booleans and Comparison Operators

Related tutorials

beginner

Python if, elif, and else Statements

Control program flow with conditions, nested branches, and clear boolean expressions.

8 min read
beginner

Python while Loops

Repeat code until a condition changes, avoid infinite loops, and use counters and sentinels safely.

8 min read

On this page

  1. How standard input works in ILoveCompiler
  2. Reading numbers
  3. Reading several values from one line
  4. Reading until empty input
  5. Practice

Run the examples

Every Python block has a Run in compiler button that opens the code in a new tab.