Class XI — Python Programming
Input / Output & Basic Arithmetic — Questions
1. Sum and Average of Two Numbers
Write a Python program to accept two numbers from the user and display their sum and average.
2. Area and Perimeter of a Rectangle
Write a Python program to accept the length and breadth of a rectangle and display its area and
perimeter.
3. Simple Interest
Write a Python program to calculate Simple Interest. Accept principal, rate of interest, and time from
the user. Use the formula: SI = (P x R x T) / 100.
4. Celsius to Fahrenheit
Write a Python program to convert a temperature from Celsius to Fahrenheit. Use the formula: F =
(C x 9/5) + 32.
5. Area of a Circle
Write a Python program to calculate the area of a circle. Accept the radius from the user and use pi
= 3.14159. Formula: Area = pi x r².
6. Swap Two Numbers
Write a Python program to swap the values of two variables entered by the user and display them
before and after swapping.
7. Quotient and Remainder
Write a Python program to accept two numbers and display the quotient and remainder when the
first number is divided by the second.
8. Square and Cube of a Number
Write a Python program to accept a number from the user and display its square and cube.
9. Total and Percentage of Marks
Write a Python program to accept marks in 5 subjects from the user. Calculate and display the total
marks and percentage. (Maximum marks per subject = 100)
10. Distance Between Two Points
Write a Python program to find the distance between two points (x1, y1) and (x2, y2). Use the
formula: distance = sqrt((x2-x1)² + (y2-y1)²). Use **0.5 for square root.
Class XI — Python Programming
Input / Output & Basic Arithmetic — Programs & Output
Program 1: Sum and Average of Two Numbers
Code:
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
total = a + b
average = total / 2
print("Sum:", total)
print("Average:", average)
Output:
Enter first number: 10
Enter second number: 20
Sum: 30.0
Average: 15.0
Program 2: Area and Perimeter of a Rectangle
Code:
length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
area = length * breadth
perimeter = 2 * (length + breadth)
print("Area:", area)
print("Perimeter:", perimeter)
Output:
Enter length: 6
Enter breadth: 4
Area: 24.0
Perimeter: 20.0
Program 3: Simple Interest
Code:
p = float(input("Enter principal: "))
r = float(input("Enter rate of interest (%): "))
t = float(input("Enter time (years): "))
si = (p * r * t) / 100
print("Simple Interest:", si)
Output:
Enter principal: 1000
Enter rate of interest (%): 5
Enter time (years): 2
Simple Interest: 100.0
Program 4: Celsius to Fahrenheit
Code:
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
Output:
Enter temperature in Celsius: 37
Temperature in Fahrenheit: 98.6
Program 5: Area of a Circle
Code:
pi = 3.14159
radius = float(input("Enter radius: "))
area = pi * radius ** 2
print("Area of Circle:", round(area, 2))
Output:
Enter radius: 7
Area of Circle: 153.94
Program 6: Swap Two Numbers
Code:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Before Swap: a =", a, "b =", b)
a, b = b, a
print("After Swap: a =", a, "b =", b)
Output:
Enter first number: 5
Enter second number: 9
Before Swap: a = 5 b = 9
After Swap: a = 9 b = 5
Program 7: Quotient and Remainder
Code:
a = int(input("Enter dividend: "))
b = int(input("Enter divisor: "))
quotient = a // b
remainder = a % b
print("Quotient:", quotient)
print("Remainder:", remainder)
Output:
Enter dividend: 17
Enter divisor: 5
Quotient: 3
Remainder: 2
Program 8: Square and Cube of a Number
Code:
num = float(input("Enter a number: "))
square = num ** 2
cube = num ** 3
print("Square:", square)
print("Cube:", cube)
Output:
Enter a number: 4
Square: 16.0
Cube: 64.0
Program 9: Total and Percentage of Marks
Code:
m1 = float(input("Enter marks in Subject 1: "))
m2 = float(input("Enter marks in Subject 2: "))
m3 = float(input("Enter marks in Subject 3: "))
m4 = float(input("Enter marks in Subject 4: "))
m5 = float(input("Enter marks in Subject 5: "))
total = m1 + m2 + m3 + m4 + m5
percentage = (total / 500) * 100
print("Total Marks:", total)
print("Percentage:", percentage, "%")
Output:
Enter marks in Subject 1: 85
Enter marks in Subject 2: 90
Enter marks in Subject 3: 78
Enter marks in Subject 4: 88
Enter marks in Subject 5: 92
Total Marks: 433.0
Percentage: 86.6 %
Program 10: Distance Between Two Points
Code:
x1 = float(input("Enter x1: "))
y1 = float(input("Enter y1: "))
x2 = float(input("Enter x2: "))
y2 = float(input("Enter y2: "))
distance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
print("Distance:", round(distance, 4))
Output:
Enter x1: 1
Enter y1: 2
Enter x2: 4
Enter y2: 6
Distance: 5.0