Input & Output
Input and output are basic building blocks of every interactive program. Python provides the input() function to accept data from the user and the print() function to display information on the screen.
What are Input and Output?
Input means receiving data from a user or another source.
Output means displaying or returning information produced by a program.
Input → Processing → Output
Name, Age, Marks
Process the data
Result displayed to user
Displaying Output using print()
The print() function is used to display text, numbers, variables, and calculated results.
print("Hello, Python!")
print("Welcome to CIIT Training Institute 👨🏫")
print(100)
Output
Hello, Python!
Welcome to CIIT Training Institute 👨🏫
100
Printing Variables
Variables can be passed directly to print().
name = "Sam"
age = 21
print(name)
print(age)
Printing Multiple Values
Multiple values can be passed to print(), separated by commas.
name = "Sam"
course = "Python"
print("Name:", name, "Course:", course)
Output
Name: Samadhan Course: Python
Using sep with print()
The sep parameter specifies what should be placed between multiple values.
print("CIIT", "Training", "Institute", sep=" - ")
Output
CIIT - Training - Institute
Using end with print()
By default, print() moves to a new line after displaying output. The end parameter can change this behavior.
print("Hello", end=" ")
print("Samadhan")
Output
Hello Samadhan
Taking Input using input()
The input() function pauses the program and waits for the user to enter some information.
name = input("Enter your name: ")
print("Hello", name)
Example
Enter your name: Samadhan
Hello Samadhan
input() Returns a String
An important point to remember is that input() returns the entered value as a string.
age = input("Enter your age: ")
print(age)
print(type(age))
Example Input
Enter your age: 25
Output
25
<class 'str'>
Taking Integer Input
If the user enters a number that needs to be used in calculations, convert it using int().
age = int(input("Enter your age: "))
print("Age:", age)
print("Next year:", age + 1)
Example
Enter your age: 25
Age: 25
Next year: 26
Taking Float Input
Use float() when the input contains decimal values.
percentage = float(
input("Enter your percentage: ")
)
print("Percentage:", percentage)
Output:
Enter your percentage: 85.5
Percentage: 85.5
Accepting Multiple Inputs
A program can accept multiple values from the user using separate input() statements.
name = input("Enter your name: ")
city = input("Enter your city: ")
print("Name:", name)
print("City:", city)
Output:
Enter your name: Pradnya
Enter your city: Pune
Name: Pradnya
City: Pune
Simple Calculator Example
Let's combine input, type conversion, variables, operators, and output to create a simple calculator.
number1 = float(input("Enter first number: "))
number2 = float(input("Enter second number: "))
addition = number1 + number2
print("Addition:", addition)
Example
Enter first number: 10
Enter second number: 20
Addition: 30.0
Using f-Strings for Output
f-strings provide a clean and readable way to combine variables with text.
name = "Samadhan"
course = "Python"
print(f"My name is {name}")
print(f"I am learning {course}")
Output:
My name is Samadhan
I am learning Python
Escape Characters
Escape characters allow special formatting inside strings.
| Escape Character | Purpose |
|---|---|
| \n | New line |
| \t | Tab space |
| \\ | Backslash |
| \" | Double quote inside a string |
| \' | Single quote inside a string |
print("CIIT Training Institute\nPython Course")
Output
CIIT Training Institute
Python Course
Student Example 🧑🎓
Let's create a small program that accepts student information for a Python course at CIIT Training Institute.
name = input("Enter student name: ")
age = int(input("Enter student age: "))
course = input("Enter course name: ")
print("\n--- Student Details ---")
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Course: {course}")
print("Institute: CIIT Training Institute")
Example
Enter student name: Samadhan
Enter student age: 25
Enter course name: Python
--- Student Details ---
Name: Samadhan
Age: 25
Course: Python
Institute: CIIT Training Institute
CIIT Learning Point
Remember the basic flow: Input → Processing → Output. The input() function collects user data, Python processes that data, and print() displays the result. Always convert numeric input when calculations are required.
CIIT Practice Task
Create a Python program that accepts a student's name and marks for three subjects. Calculate the total and percentage, then display the result.
name = input("Enter student name: ")
math = float(input("Enter Math marks: "))
python = float(input("Enter Python marks: "))
sql = float(input("Enter SQL marks: "))
total = math + python + sql
percentage = total / 3
print("\nStudent:", name)
print("Total:", total)
print("Percentage:", percentage)
Output:
Enter student name: Samadhan
Enter Math marks: 80
Enter Python marks: 90
Enter SQL marks: 85
Student: Samadhan
Total: 255.0
Percentage: 85.0
Summary :
Python uses print() to display output and input() to accept data from the user. You learned how to display variables, accept string and numeric input, convert input values, use sep and end, format output with f-strings, and build simple interactive programs using the Input → Processing → Output flow.