← Python from Scratch
Lesson 5 of 78 · 10 XP
Input and output
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
input() pauses the program and waits until the user types a line and presses Enter. You can store the value they typed:
name = input("What is your name? ")
print("Hello,", name)
The text in input("...") is a prompt; it is printed before the input. It doesn't get in the way of the automatic tests, so feel free to write one.
print() has some useful settings:
print("a", "b", "c") # a b c — separated by spaces
print("a", "b", "c", sep="-") # a-b-c — your own separator
print("Loading", end="...") # no line break at the end
print("done") # Loading...done
To join text without a space, use +:
print("Hello, " + name + "!")
Task. Read a name and print a greeting in the form Hello, Roma! — with a comma, a space and an exclamation mark, and no extra spaces.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.