Python Input and Output

Hey friends 👋 welcome back, In the last lesson, we learned about basic operations, Today, we are going to learn about input and output, which allows our programs to get information from users and display results, This is important because most programs need to interact with people.

Output with print()

The print() function is used to display information on the screen. Example:

name = "Yusuf" age = 14 print("My name is", name) print("I am", age, "years old")

Output:

My name is Yusuf I am 14 years old

Input from the User

The input() function lets us get information from the user. Example:

name = input("Enter your name: ") age = input("Enter your age: ") print("Hello", name, "You are", age, "years old")

Explanation:

  • input() displays a message and waits for the user to type something

  • The value entered is always stored as a string, even if it looks like a number

Converting Input to Numbers

If you want to do calculations with user input, you need to convert it to a number using int() or float(). Example:

num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) sum = num1 + num2 print("The sum is", sum)

Output Example:

Enter first number: 10 Enter second number: 5 The sum is 15

Practice Time

Create a Python file called input_output.py and try these exercises, 1, Ask the user for their name and greet them, 2, Ask the user for two numbers and print their sum, 3, Ask the user for their favorite color and print a message with it, 4, Ask for three numbers and print their average

Great job, You just learned how to get input from users and display output in Python, In the next lesson, we will explore Python Conditional Statements, where we will learn how to make decisions in programs using if, elif, and else, We will soon be launching our YouTube channel, where we are going to post step-by-step video tutorials on Python and other tech skills, These videos will make learning easier and more visual, helping beginners follow along confidently.