📝 Overview
In this lesson, you’ll learn how to get input from the user and display output using Python’s built-in functions. This helps make your programs interactive and dynamic.
🎯 What You’ll Learn
-
How to use the
input()
function to get user input -
How to use the
print()
function to show output -
How to combine and format text and variables
-
Common input/output (I/O) examples
📥 1. Getting User Input
Use the input()
function to ask the user something:
🔍 What’s happening here?
-
The
input()
function displays a message and waits for the user to type something. -
Whatever they type is stored as a string in the variable (
name
).
📤 2. Displaying Output
The print()
function is used to show results or messages on the screen.
You can also print multiple things:
🔢 3. Type Conversion
Input is always a string, so if you need a number, convert it:
-
int()
converts to integer -
float()
converts to float (decimal)
🎨 4. Formatting Output
You can use f-strings
for cleaner output:
This is more readable and easier to maintain.
🧠 Practice Task
Build a small form using input()
:
⚠️ Common Mistakes to Avoid
-
Forgetting to convert input to number (
int
,float
) -
Using commas incorrectly in
print()
-
Using
+
with different data types ("Age: " + 18
will cause error!)
✅ Summary
-
input()
gets data from the user -
print()
shows output -
Always convert input if you expect a number
-
Use f-strings for clean formatting
⏭️ Next Lesson Preview
→ Conditional Statements in Python (if
, else
, elif
)