Skip to content
dreamcode
dreamcode
Map
input()
Lesson 7 of 77
+15 XP on finish
PYTHON BASICSChapter 1 · Python Basics

Asking for input

input() pauses the program and returns whatever the user types, always as a string. Put a message in the parentheses to show a prompt. In this editor you type your answers into the Input box under the code: one line for each input() call.

Worked example

How it reads

  • input("...") shows the prompt and returns the typed text
  • Wrap it in int(...) when you need a number
  • Each input() reads the next line of the Input box
Common mistakes
  • age = input("Age? ") followed by age + 1 raises TypeError: you cannot add a number to a string.
Cloud tip: Always convert numeric input: int(input(...)). Without it, age + 1 fails because age is text.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

The Input box already holds two lines. Read the second one as a number of stars with another input(), then print exactly violet sky with 5 stars.

Press Run to check your work.