Interaction is what makes a program useful. In Python, we use two primary functions to talk to the user: print() for output and input() for input.
1. Output with print()
The print() function sends data to the screen. You can print multiple items at once and even format them elegantly.
Comma Separation: Automatically adds a space between items.
F-Strings (Formatted Strings): The modern way to inject variables into text using
{}.
2. Input with input()
The input() function pauses the program and waits for the user to type something.
Crucial Rule:
input()always treats everything as a String. If you want to do math with a user's input, you must convert it usingint()orfloat().
# --- OUTPUT ---
name = "Alice"
version = 3.12
# Using an f-string (the most popular way)
print(f"Hello {name}, you are using Python {version}")
# --- INPUT ---
# Getting a string
user_city = input("Where do you live? ")
# Getting a number (Casting is required!)
age_str = input("How old are you? ")
age = int(age_str) # Convert string to integer
print(f"In 5 years, you will be {age + 5} years old in {user_city}!")