Python Input and Output Practice Questions with Solutions

Python programs become interactive by taking input from users and displaying output on the screen. This practice set covers the input() and print() functions, type conversion, and formatted output through beginner-friendly Python Input and Output Practice Questions with solutions.


1. Python Program to Accept and Display User Name

Problem Statement

Write a Python program to accept the user’s name and display a welcome message.

Expected Output

Enter your name: Alex
Welcome, Alex!

Python Solution

name = input("Enter your name: ")

print("Welcome,", name + "!")

Explanation

The input() function accepts user input as a string. The print() function displays the output.

Concepts Covered

  • input()
  • print()

2. Python Program to Accept Two Numbers and Display Their Sum

Problem Statement

Write a Python program to accept two numbers from the user and display their sum.

Expected Output

Enter first number: 15
Enter second number: 20

Sum: 35

Python Solution

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

print("Sum:", num1 + num2)

Explanation

The input() function returns a string, so int() is used to convert it into an integer.

Concepts Covered

  • input()
  • int()
  • Addition

3. Python Program to Accept Integer, Float, and String Input

Problem Statement

Write a Python program to accept a student’s name, age, and percentage from the user and display them.

Expected Output

Enter name: Emma
Enter age: 20
Enter percentage: 89.5

Student Name: Emma
Age: 20
Percentage: 89.5

Python Solution

name = input("Enter name: ")
age = int(input("Enter age: "))
percentage = float(input("Enter percentage: "))

print("\nStudent Name:", name)
print("Age:", age)
print("Percentage:", percentage)

Explanation

Use int() for whole numbers and float() for decimal values.

Concepts Covered

  • String Input
  • Integer Input
  • Float Input

4. Python Program to Calculate the Area of a Rectangle

Problem Statement

Write a Python program to accept the length and width of a rectangle and calculate its area.

Expected Output

Enter length: 8
Enter width: 5

Area: 40

Python Solution

length = float(input("Enter length: "))
width = float(input("Enter width: "))

area = length * width

print("Area:", area)

Explanation

The program accepts two values and calculates the area using the formula:

Area = Length × Width

Concepts Covered

  • User Input
  • Variables
  • Arithmetic Operator

5. Python Program to Calculate Simple Interest

Problem Statement

Accept principal, rate, and time from the user and calculate simple interest.

Expected Output

Enter Principal: 10000
Enter Rate: 8
Enter Time: 2

Simple Interest: 1600.0

Python Solution

principal = float(input("Enter Principal: "))
rate = float(input("Enter Rate: "))
time = float(input("Enter Time: "))

si = (principal * rate * time) / 100

print("Simple Interest:", si)

Explanation

The formula used is:

Simple Interest = (Principal × Rate × Time) / 100

Concepts Covered

  • User Input
  • Formula
  • Arithmetic Operators

6. Python Program to Calculate the Average of Three Numbers

Problem Statement

Write a Python program to accept three numbers and calculate their average.

Expected Output

Enter first number: 10
Enter second number: 20
Enter third number: 30

Average: 20.0

Python Solution

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

average = (num1 + num2 + num3) / 3

print("Average:", average)

Explanation

The average is calculated by dividing the total sum by the number of values.

Concepts Covered

  • User Input
  • Arithmetic Operators

7. Python Program to Display User Information

Problem Statement

Accept the following details from the user and display them in a formatted output.

  • Name
  • Age
  • City

Expected Output

Enter Name: Alex
Enter Age: 22
Enter City: Delhi

------ User Information ------
Name : Alex
Age  : 22
City : Delhi

Python Solution

name = input("Enter Name: ")
age = int(input("Enter Age: "))
city = input("Enter City: ")

print("\n------ User Information ------")
print("Name :", name)
print("Age  :", age)
print("City :", city)

Explanation

The print() function can be used to create clean and readable console output.

Concepts Covered

  • Input
  • Output Formatting

8. Python Program to Convert Temperature from Celsius to Fahrenheit

Problem Statement

Write a Python program to accept temperature in Celsius and convert it into Fahrenheit.

Formula:

Fahrenheit = (Celsius × 9 / 5) + 32

Expected Output

Enter Celsius: 25

Fahrenheit: 77.0

Python Solution

celsius = float(input("Enter Celsius: "))

fahrenheit = (celsius * 9 / 5) + 32

print("Fahrenheit:", fahrenheit)

Explanation

The formula converts Celsius temperature into Fahrenheit.

Concepts Covered

  • User Input
  • Formula
  • Arithmetic Operators

9. Python Program to Calculate Total Marks and Percentage

Problem Statement

Accept marks of five subjects from the user. Calculate the total marks and percentage.

Python Solution

sub1 = float(input("Subject 1: "))
sub2 = float(input("Subject 2: "))
sub3 = float(input("Subject 3: "))
sub4 = float(input("Subject 4: "))
sub5 = float(input("Subject 5: "))

total = sub1 + sub2 + sub3 + sub4 + sub5
percentage = total / 5

print("Total Marks:", total)
print("Percentage:", percentage)

Sample Output

Total Marks: 425.0
Percentage: 85.0

Explanation

The program accepts five subject marks and calculates both the total and average percentage.

Concepts Covered

  • Multiple Inputs
  • Variables
  • Arithmetic Operators

10. Python Program to Create a Student Registration Form

Problem Statement

Write a Python program to accept the following details and display them in a formatted registration form.

  • Name
  • Age
  • Course
  • Email

Python Solution

name = input("Enter Name: ")
age = int(input("Enter Age: "))
course = input("Enter Course: ")
email = input("Enter Email: ")

print("\n===== Student Registration =====")
print("Name   :", name)
print("Age    :", age)
print("Course :", course)
print("Email  :", email)

Sample Output

===== Student Registration =====
Name   : Alex
Age    : 20
Course : Python Programming
Email  : alex@example.com

Explanation

This program combines multiple user inputs and displays them in a structured format.

Concepts Covered

  • Multiple User Inputs
  • Output Formatting
  • Variables

11. Python Program to Create a Simple Student Information System

Problem Statement

Write a Python program to accept a student’s name, roll number, and marks from the user and display them in a formatted output.

Python Solution

name = input("Enter Student Name: ")
roll = int(input("Enter Roll Number: "))
marks = float(input("Enter Marks: "))

print("\n----- Student Details -----")
print("Name :", name)
print("Roll Number :", roll)
print("Marks :", marks)

Sample Output

Enter Student Name: Rahul
Enter Roll Number: 101
Enter Marks: 87.5

----- Student Details -----
Name : Rahul
Roll Number : 101
Marks : 87.5

Explanation

The program accepts different types of input and displays them in a readable format.

Concepts Covered

  • input()
  • print()
  • int()
  • float()
  • Formatted Output

12. Python Program to Calculate Total, Average, and Percentage

Problem Statement

Write a Python program to accept marks of five subjects and calculate the total marks, average marks, and percentage.

Python Solution

m1 = float(input("Enter Marks of Subject 1: "))
m2 = float(input("Enter Marks of Subject 2: "))
m3 = float(input("Enter Marks of Subject 3: "))
m4 = float(input("Enter Marks of Subject 4: "))
m5 = float(input("Enter Marks of Subject 5: "))

total = m1 + m2 + m3 + m4 + m5
average = total / 5
percentage = total / 5

print("Total Marks:", total)
print("Average:", average)
print("Percentage:", percentage, "%")

Sample Output

Enter Marks of Subject 1: 80
Enter Marks of Subject 2: 75
Enter Marks of Subject 3: 90
Enter Marks of Subject 4: 85
Enter Marks of Subject 5: 70

Total Marks: 400.0
Average: 80.0
Percentage: 80.0 %

Explanation

The program takes multiple user inputs and performs arithmetic calculations before displaying the results.

Concepts Covered

  • User Input
  • Arithmetic Operations
  • Formatted Output

13. Python Program to Convert Temperature from Celsius to Fahrenheit

Problem Statement

Write a Python program to accept temperature in Celsius and convert it into Fahrenheit.

Python Solution

celsius = float(input("Enter Temperature in Celsius: "))

fahrenheit = (celsius * 9 / 5) + 32

print("Temperature in Fahrenheit:", fahrenheit)

Sample Output

Enter Temperature in Celsius: 30
Temperature in Fahrenheit: 86.0

Explanation

The program reads temperature from the user, applies the conversion formula, and prints the result.

Concepts Covered

  • float()
  • User Input
  • Output Formatting

14. Python Program to Print User Details in Multiple Lines

Problem Statement

Write a Python program to accept personal details and display them in a well-formatted report.

Python Solution

name = input("Enter Name: ")
age = int(input("Enter Age: "))
city = input("Enter City: ")

print("\n===== User Profile =====")
print("Name :", name)
print("Age  :", age)
print("City :", city)

Sample Output

Enter Name: Rohan
Enter Age: 22
Enter City: Delhi

===== User Profile =====
Name : Rohan
Age  : 22
City : Delhi

Explanation

This example demonstrates how to organize output using multiple print() statements.

Concepts Covered

  • print()
  • Formatting Output
  • User Input

15. Python Program to Create a Simple Bill Generator

Problem Statement

Write a Python program to accept the product name, quantity, and price per item, then calculate and display the total bill.

Python Solution

product = input("Enter Product Name: ")
quantity = int(input("Enter Quantity: "))
price = float(input("Enter Price Per Item: "))

total = quantity * price

print("\n------ Bill ------")
print("Product :", product)
print("Quantity:", quantity)
print("Price   :", price)
print("Total Bill: ₹", total)

Sample Output

Enter Product Name: Laptop
Enter Quantity: 2
Enter Price Per Item: 45000

------ Bill ------
Product : Laptop
Quantity: 2
Price   : 45000.0
Total Bill: ₹ 90000.0

Explanation

This project combines input, arithmetic operations, and formatted output to generate a simple bill.

Concepts Covered

  • input()
  • print()
  • Arithmetic Operations
  • Real-world Application

Frequently Asked Questions (FAQs)

1. What is input and output in Python?

Input allows users to enter data into a program using the input() function, while output displays information to the screen using the print() function.


2. Which function is used to take input from the user in Python?

The input() function is used to accept user input. By default, it returns the input as a string.

Example:

name = input("Enter your name: ")

3. Which function is used to display output in Python?

The print() function is used to display text, variables, calculations, and other information on the screen.

Example:

print("Welcome to Python!")

4. Why does the input() function return a string?

The input() function always returns data as a string, regardless of whether the user enters numbers or text. To perform calculations, you must convert the input using functions like int() or float().


5. How do I accept integer and decimal input in Python?

Use int() for whole numbers and float() for decimal numbers.

Example:

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

6. What is formatted output in Python?

Formatted output improves the readability of displayed data. You can use f-strings, commas, or multiple print() statements to format output.

Example:

name = "Alice"
age = 22

print(f"Name: {name}")
print(f"Age: {age}")

7. Why are input and output important in Python?

Input and output are fundamental concepts in Python programming. They allow programs to interact with users, collect data, process information, and display meaningful results. They are widely used in web applications, automation, data analysis, software development, and machine learning projects.

Chapter Summary

After completing this chapter, you have learned:

  • input() function
  • print() function
  • int() and float() conversion
  • Accepting multiple user inputs
  • Formatted console output
  • Real-world input-based Python programs

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top