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:
Output:
Input from the User
The input() function lets us get information from the user. Example:
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:
Output Example:
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.
0 Comments