Python Input and Output for Class 11 Students
In Python, input() and print() are two important functions that beginners should understand. The input() function is used to take information from the user, while print() is used to display output on the screen.
If you are starting Python for Class 11, you can also read our guide:
Python Programming for Class 11 Students: What You Should Learn
1. Displaying Output Using print()
The print() function is used to display text, numbers and variable values on the screen.
print("Hello World")
print(10)
name = "Python"
print("Welcome to", name)
Output:
Hello World 10 Welcome to Python
2. Taking Input Using input()
The input() function allows a program to take information from the user.
name = input("Enter your name: ")
print("Hello", name)
If the user enters Minkal, the output will be:
Enter your name: Minkal Hello Minkal
3. Taking Numbers as Input
One important thing to remember is that input() normally takes the entered value as a string. To work with numbers, we can use int() or float().
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum = num1 + num2
print("Sum is:", sum)
For example, if the user enters 5 and 3:
Enter first number: 5 Enter second number: 3 Sum is: 8
4. Using Input in a Simple Program
We can use multiple inputs to create a simple student details program.
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Name:", name)
print("Age:", age)
This program takes the student's name and age and then displays both values.
5. Using Input and Output Together
Most beginner Python programs use input() to collect information and print() to display the result.
For example, we can create a program to calculate the total of two numbers:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
total = a + b
print("Total =", total)
Practice These Examples
The best way to understand input() and print() is to type these programs yourself and run them.
- Take your name as input and print a welcome message.
- Take two numbers and calculate their sum.
- Take a student's name and age and display them.
- Take three numbers and calculate their total.
- Take the user's city and display a message.
What's Next?
Once you understand input and output, you can start combining them with operators, conditional statements and loops to create more useful Python programs.
Also Read: 10 Beginner Python Programs for Class 11 Students
Also Read: 5 Common Python Mistakes Class 11 CBSE Students Should Avoid
Also Read: Why Should Students Learn Python?
Also Read: Python Variables Explained with Simple Examples
Learn Python Through Practical Coding
Regular coding practice helps Class 11 students understand Python concepts and improve their programming skills.
great
ReplyDelete