HomeCourseModule 03 › Talking to the user — input() and print()

Talking to the user — input() and print()

Module 03 · Variables and Data Types6 min readBeginner

What you'll learn

  • Use input() to read text from the user
  • Format print() output cleanly
  • Combine the two into a working mini-program

input() — ask a question

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

When this runs in a script or terminal, the prompt appears, the program pauses, the user types something, hits Enter, and the typed text is stored in name. Always as a string — even if they typed digits.

print() — talk back

print("Hello")
print("a", "b", "c")           # a b c
print("a", "b", "c", sep="-")  # a-b-c
print("first")
print("second")
print("third", end=" ")
print("on the same line")

A complete mini-program

# tip_calculator.py
bill = float(input("Bill amount: "))
tip_pct = float(input("Tip percent: "))
people = int(input("How many people? "))

tip = bill * tip_pct / 100
total = bill + tip
per_person = total / people

print()
print(f"Total: ${total:,.2f}")
print(f"Each:  ${per_person:,.2f}")
💡 input() in Jupyter
The same input() works in a Jupyter notebook — a little prompt appears under the cell.

Key takeaways

  • input("prompt: ") reads a line from the user; the result is always a string.
  • print() can take any number of values, separated by sep=, terminated by end=.
  • Combine them for tiny command-line tools.

Build a unit converter

Ask the user for kilometres, convert to miles (km × 0.621), print the result.

📹 Video walkthrough
A video walkthrough of this lesson will be embedded here. Until then, the written walkthrough above mirrors what the video will cover step-for-step.