1) Friendly introduction
Imagine chatting with your computer. You say something, it answers back. That's exactly what "input" (you talk to the computer) and "output" (the computer talks to you) are about. In Python, we do this with two superstar functions:
- print() for output
- input() for input
By the end of this lesson, you'll make small programs that ask questions and reply smartly!
2) Output: showing messages with print()
- print() writes text or values on the screen.
Example 1: printing text
print("Hello, world!")Example 2: printing numbers and text together
print("I am learning Python!")
print(7)
print("The answer is", 7)Tip: You can use commas to print different things together. Python adds spaces for you.
Example 3: using variables
name = "Maya"
print("Hi", name)Example 4: f-strings (a handy way to mix text and variables)
name = "Maya"
print(f"Hi {name}, welcome to PyVerse!")3) Input: asking the user for information
- input() shows a prompt and waits for the user to type something.
- Whatever the user types is returned as text (a "string").
Example 1: basic input
name = input("What is your name? ")
print("Nice to meet you,", name)Example 2: input always returns text
food = input("What is your favorite food? ")
print("Yum! I like", food, "too.")4) Converting input to numbers (int and float)
Because input() gives you text, you need to convert it if you want to do math.
- int(...) converts text to a whole number (like 12)
- float(...) converts text to a decimal number (like 12.5)
Example: adding 1 to an age
age = int(input("How old are you? "))
print(f"Next year you will be {age + 1}")Example: adding two numbers
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
print("The sum is", a + b)5) Common beginner tips
- If you try "2" + "3", you get "23" (that's text glued together), not 5.
- If you see an error when doing "Score: " + 10, it's because you mixed text and number with +.
Fix it by using commas: print("Score:", 10)
Or convert: print("Score: " + str(10))
Or use f-strings: print(f"Score: {10}")
6) Mini exercise: Quick Greeter + Age Helper
Your task:
- Ask the user for their name.
- Ask for their age (as a whole number).
- Print a friendly message using an f-string that says hello and tells them how old they'll be next year.
Example run (what it might look like):
What is your name? Alex
How old are you? 13
Hello Alex! Next year you will be 14.Hint steps:
- name = input("What is your name? ")
- age = int(input("How old are you? "))
- print(f"Hello {name}! Next year you will be {age + 1}.")
Optional challenge:
- Also ask for a favorite color and include it in the final message.
7) Short summary
- Use print() to show information on the screen.
- Use input("prompt") to ask the user for something; it returns text.
- Convert input to numbers with int() or float() if you want to do math.
- f-strings like f"Hello {name}" make it easy to combine text and variables.
You're ready to make interactive programs—go chat with your code!