Paramclasses Academy - Blog

Tutorials Details

WHAT IS INPUT AND OUTPUT?

WHAT IS INPUT AND OUTPUT?

October 16, 2026

WHAT IS INPUT AND OUTPUT?

WHAT IS INPUT?

Input means providing data to a program.

WHAT IS OUTPUT?

Output means displaying the result or information produced by a program.

WHY DO WE USE INPUT AND OUTPUT?

1. To collect information from users.
2. To display results.
3. To create interactive programs.
4. To accept customer and employee details.
5. To calculate bills and salaries.
6. To build registration and login systems.

Example:

name = input("Enter your name: ")
print("Welcome", name)

Sample Input:

Enter your name: Rahul

Output:

Welcome Rahul

==================================================
2. WHAT IS THE input() FUNCTION?
==================================================

The input() function accepts information entered by a user.

SYNTAX:

variable = input("Enter a value: ")

IMPORTANT:

The input() function returns a string by default.

EXAMPLE:

name = input("Enter your name: ")

print(name)

Sample Input:

Enter your name: Amit

Output:

Amit

EXPLANATION:

input() displays a prompt.
The user enters information.
The entered text is stored in the variable name.
print() displays the stored information.

==================================================
3. TAKING INTEGER INPUT
==================================================

WHAT IS int(input())?

It accepts user input and converts it to an integer.

SYNTAX:

variable = int(input("Enter a number: "))

EXAMPLE:

age = int(input("Enter your age: "))

print("Your age is:", age)

Sample Input:

Enter your age: 25

Output:

Your age is: 25

REAL-TIME EXAMPLE:

Accept the number of products purchased by a customer.

quantity = int(input("Enter quantity: "))

print("Quantity:", quantity)

Sample Input:

Enter quantity: 5

Output:

Quantity: 5

NOTE:

If the user enters invalid integer text, Python raises ValueError.

==================================================
4. TAKING FLOAT INPUT
==================================================

WHAT IS float(input())?

It accepts user input and converts it to a floating-point number.

SYNTAX:

variable = float(input("Enter a decimal number: "))

EXAMPLE:

price = float(input("Enter product price: "))

print("Product price:", price)

Sample Input:

Enter product price: 99.50

Output:

Product price: 99.5

REAL-TIME EXAMPLE:

Accept an employee's monthly salary.

salary = float(input("Enter monthly salary: "))

print("Monthly salary:", salary)

Sample Input:

Enter monthly salary: 25000.50

Output:

Monthly salary: 25000.5

==================================================
5. WHAT IS THE print() FUNCTION?
==================================================

The print() function displays information on the screen.

SYNTAX:

print(value)

EXAMPLE:

print("Hello Python")
print(100)
print(25.5)
print(True)

OUTPUT:

Hello Python
100
25.5
True

You can display strings, numbers, Boolean values, variables, and expressions.

==================================================
6. DISPLAY MULTIPLE VALUES
==================================================

Python allows multiple values to be displayed in one print() statement.

EXAMPLE:

name = "Rahul"
age = 25
city = "Raipur"

print(name, age, city)

OUTPUT:

Rahul 25 Raipur

EXAMPLE WITH LABELS:

print("Name:", name)
print("Age:", age)
print("City:", city)

OUTPUT:

Name: Rahul
Age: 25
City: Raipur

REAL-TIME USE:

Display customer details, employee information, student results, and product details.

==================================================
7. USING SEPARATOR IN print()
==================================================

WHAT IS sep?

The sep parameter specifies the text placed between values displayed by print().

SYNTAX:

print(value1, value2, sep="separator")

EXAMPLE:

print("2026", "10", "16", sep="-")

OUTPUT:

2026-10-16

ANOTHER EXAMPLE:

print("Python", "Java", "SQL", sep=" | ")

OUTPUT:

Python | Java | SQL

REAL-TIME EXAMPLE:

Display a formatted phone number.

country_code = "+91"
mobile = "9876543210"

print(country_code, mobile, sep="-")

OUTPUT:

+91-9876543210

==================================================
8. USING END IN print()
==================================================

WHAT IS end?

The end parameter specifies what print() displays at the end of its output.

By default, print() ends with a newline.

EXAMPLE:

print("Hello", end=" ")
print("World")

OUTPUT:

Hello World

ANOTHER EXAMPLE:

print("Python", end=" - ")
print("Programming")

OUTPUT:

Python - Programming

REAL-TIME USE:

Display progress messages or combine output on one line.

==================================================
9. OUTPUT FORMATTING USING f-STRINGS
==================================================

WHAT IS AN f-STRING?

An f-string allows variables and expressions to be inserted directly into text.

Available in Python 3.6 and later.

SYNTAX:

print(f"Text {variable}")

EXAMPLE:

name = "Rahul"
age = 25

print(f"My name is {name} and I am {age} years old.")

OUTPUT:

My name is Rahul and I am 25 years old.

EXAMPLE WITH CALCULATION:

a = 10
b = 20

print(f"Total: {a + b}")

OUTPUT:

Total: 30

REAL-TIME EXAMPLE:

product = "Laptop"
price = 50000

print(f"Product: {product}, Price: Rs. {price}")

OUTPUT:

Product: Laptop, Price: Rs. 50000

==================================================
10. FORMATTING DECIMAL VALUES
==================================================

You can format decimal numbers using f-strings.

EXAMPLE:

price = 99.5678

print(f"Price: {price:.2f}")

OUTPUT:

Price: 99.57

EXPLANATION:

.2f displays a floating-point number rounded to two decimal places.

REAL-TIME EXAMPLE:

amount = 1250.5

print(f"Total amount: Rs. {amount:.2f}")

OUTPUT:

Total amount: Rs. 1250.50

==================================================
11. TAKING MULTIPLE INPUTS
==================================================

EXAMPLE 1: TAKING TWO SEPARATE INPUTS

name = input("Enter your name: ")
city = input("Enter your city: ")

print(f"Name: {name}")
print(f"City: {city}")

Sample Input:

Enter your name: Amit
Enter your city: Raipur

Output:

Name: Amit
City: Raipur

EXAMPLE 2: TAKING TWO INTEGERS IN ONE LINE

a, b = map(int, input("Enter two numbers: ").split())

print("Sum:", a + b)

Sample Input:

Enter two numbers: 10 20

Output:

Sum: 30

EXPLANATION:

input() accepts a line of text.
split() separates the text using whitespace.
map(int, ...) converts each value to an integer.
The two integers are assigned to a and b.

==================================================
12. TYPE CONVERSION WITH USER INPUT
==================================================

IMPORTANT RULE:

input() returns a string, even if the user enters digits.

EXAMPLE:

a = input("Enter first number: ")
b = input("Enter second number: ")

print(a + b)

Sample Input:

Enter first number: 10
Enter second number: 20

Output:

1020

WHY?

Both values are strings, so + joins the text instead of adding numbers.

CORRECT PROGRAM:

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Sum:", a + b)

Sample Input:

Enter first number: 10
Enter second number: 20

Output:

Sum: 30

==================================================
13. REAL-TIME PROJECT: CUSTOMER REGISTRATION
==================================================

SCENARIO:

A business wants to collect a customer's name, age, and city.

PROGRAM:

name = input("Enter customer name: ")
age = int(input("Enter customer age: "))
city = input("Enter customer city: ")

print("==============================")
print("CUSTOMER REGISTRATION")
print("==============================")
print(f"Name: {name}")
print(f"Age: {age}")
print(f"City: {city}")
print("Registration completed")

SAMPLE INPUT:

Enter customer name: Rahul Sharma
Enter customer age: 28
Enter customer city: Raipur

OUTPUT:

==============================
CUSTOMER REGISTRATION
==============================
Name: Rahul Sharma
Age: 28
City: Raipur
Registration completed

CONCEPTS USED:

input()
int()
print()
Variables
f-strings

NOTE:

This is a basic demonstration. A real registration system should validate input and store information securely.

==================================================
14. REAL-TIME PROJECT: BILLING CALCULATOR
==================================================

SCENARIO:

A shop needs to calculate the total price of purchased products.

PROGRAM:

product = input("Enter product name: ")
price = float(input("Enter product price: "))
quantity = int(input("Enter quantity: "))

subtotal = price * quantity

print("==============================")
print("CUSTOMER BILL")
print("==============================")
print(f"Product: {product}")
print(f"Price per item: Rs. {price:.2f}")
print(f"Quantity: {quantity}")
print(f"Subtotal: Rs. {subtotal:.2f}")

SAMPLE INPUT:

Enter product name: Notebook
Enter product price: 50
Enter quantity: 4

OUTPUT:

==============================
CUSTOMER BILL
==============================
Product: Notebook
Price per item: Rs. 50.00
Quantity: 4
Subtotal: Rs. 200.00

REAL-TIME APPLICATION:

This basic structure can be extended to include taxes, discounts, payment methods, and invoice numbers.

==================================================
15. REAL-TIME PROJECT: STUDENT MARKS CALCULATOR
==================================================

SCENARIO:

A teacher wants to calculate the total and percentage for three subjects.

PROGRAM:

name = input("Enter student name: ")

maths = float(input("Enter Maths marks: "))
science = float(input("Enter Science marks: "))
english = float(input("Enter English marks: "))

total = maths + science + english
percentage = total / 300 * 100

print("==============================")
print("STUDENT RESULT")
print("==============================")
print(f"Student Name: {name}")
print(f"Total Marks: {total} / 300")
print(f"Percentage: {percentage:.2f}%")

SAMPLE INPUT:

Enter student name: Rahul
Enter Maths marks: 80
Enter Science marks: 75
Enter English marks: 85

OUTPUT:

==============================
STUDENT RESULT
==============================
Student Name: Rahul
Total Marks: 240.0 / 300
Percentage: 80.00%

NOTE:

This example assumes three subjects, each with a maximum of 100 marks.

==================================================
16. HANDLING INVALID INPUT
==================================================

WHAT IS INPUT VALIDATION?

Input validation checks whether entered data is acceptable before using it.

EXAMPLE:

try:
    age = int(input("Enter your age: "))
    print(f"Your age is {age}")
except ValueError:
    print("Please enter a valid whole number")

VALID INPUT:

Enter your age: 25

OUTPUT:

Your age is 25

INVALID INPUT:

Enter your age: twenty

OUTPUT:

Please enter a valid whole number

EXPLANATION:

try runs the code that might fail.
except handles the specified error.
ValueError occurs when the input cannot be converted to an integer.

REAL-TIME USE:

Validate customer ages, product quantities, prices, and numeric form fields.

==================================================
17. COMMON BEGINNER MISTAKES
==================================================

MISTAKE 1: FORGETTING TYPE CONVERSION

Incorrect:

age = input("Enter age: ")
print(age + 1)

This causes TypeError because age is a string.

Correct:

age = int(input("Enter age: "))
print(age + 1)

------------------------------------------

MISTAKE 2: FORGETTING QUOTATION MARKS

Incorrect:

print(Hello)

This raises NameError if Hello is not defined.

Correct:

print("Hello")

------------------------------------------

MISTAKE 3: INVALID NUMERIC INPUT

Example:

price = float(input("Enter price: "))

If the user enters "abc", Python raises ValueError.

Solution:

Use try and except to handle invalid input.

------------------------------------------

MISTAKE 4: CONFUSING + WITH NUMERIC ADDITION

Example:

print("10" + "20")

Output:

1020

Correct numeric addition:

print(int("10") + int("20"))

Output:

30

==================================================
18. PRACTICE PROGRAMS
==================================================

PROGRAM 1: PERSONAL DETAILS

Ask the user for their name, age, and city.
Display all details using f-strings.

PROGRAM 2: ADD TWO NUMBERS

Take two integers as input.
Display their sum.

PROGRAM 3: SIMPLE CALCULATOR

Take two numbers as input.
Display addition, subtraction, multiplication, and division.
Handle division by zero.

PROGRAM 4: RECTANGLE AREA

Take length and width as input.
Calculate and display the area.

Formula:

Area = Length * Width

PROGRAM 5: SHOPPING BILL

Ask for a product name, price, and quantity.
Calculate and display the subtotal.

PROGRAM 6: DISCOUNT CALCULATOR

Take the original price and discount percentage.
Calculate the discount and final price.

Formula:

Discount = Price * Discount Percentage / 100
Final Price = Price - Discount

PROGRAM 7: STUDENT RESULT

Ask for marks in three subjects.
Calculate total and percentage.

PROGRAM 8: TEMPERATURE CONVERTER

Ask for temperature in Celsius.
Convert it to Fahrenheit.

Formula:

Fahrenheit = (Celsius * 9 / 5) + 32

PROGRAM 9: EMPLOYEE SALARY

Ask for employee name and monthly salary.
Calculate annual salary.

Formula:

Annual Salary = Monthly Salary * 12

PROGRAM 10: CUSTOMER REGISTRATION

Collect customer name, age, phone number, and city.
Display the details in a formatted layout.

==================================================
19. MODULE 4 QUIZ
==================================================

Q1. Which function accepts user input?

A. print()
B. input()
C. type()

Answer: B. input()

Q2. What does input() return by default?

A. int
B. float
C. str

Answer: C. str

Q3. Which function converts suitable input to an integer?

A. int()
B. print()
C. input()

Answer: A. int()

Q4. Which parameter changes the separator in print()?

A. end
B. sep
C. split

Answer: B. sep

Q5. Which parameter controls the ending of print()?

A. end
B. sep
C. type

Answer: A. end

Q6. Which syntax is an f-string?

A. f"Hello {name}"
B. "Hello" + f
C. format f("Hello")

Answer: A. f"Hello {name}"

Q7. What is the output?

a = input()
b = input()
print(a + b)

If the inputs are 10 and 20:

Answer: 1020

Q8. Which block can handle invalid integer input?

A. if only
B. try and except
C. print only

Answer: B. try and except

Q9. What does {:.2f} format?

A. Two decimal places
B. Two variables
C. Two input lines

Answer: A. Two decimal places

Q10. What error may occur when float("abc") is executed?

A. TypeError
B. ValueError
C. NameError

Answer: B. ValueError

==================================================
20. MODULE 4 ASSIGNMENT
==================================================

Complete these tasks independently:

1. Write a program that accepts and displays your name.
2. Take two numbers and calculate their sum.
3. Build a simple calculator.
4. Create a customer registration form.
5. Create a product billing calculator.
6. Create a student marks calculator.
7. Format output using f-strings.
8. Display multiple values using sep.
9. Display multiple messages using end.
10. Handle invalid numeric input with try and except.
11. Create an employee salary calculator.
12. Create a Celsius-to-Fahrenheit converter.

==================================================
21. MODULE 4 SUMMARY
==================================================

In this module, you learned:

1. What input and output mean.
2. The input() function.
3. The print() function.
4. Taking integer and float input.
5. Displaying multiple values.
6. Using sep and end.
7. Formatting output with f-strings.
8. Formatting decimal numbers.
9. Taking multiple inputs.
10. Type conversion.
11. Handling invalid input.
12. Real-time customer registration.
13. Billing and student marks calculators.
14. Practice programs, quizzes, and assignments.