By Anjeev Kr Singh – Computer Science Educator
Published on : August 30, 2021 | Updated on : February 2, 2022
NCERT Book Exercise Solution
Class 11 Computer Science
Chapter 5 – Getting Started with Python
15. Write a program to swap two numbers without using a third variable.
Answer: Swapping of two numbers without third variable.
x = 25
y = 30
print("Before Swap: x = ", x, "y = ", y)
x, y = y, x
print("After Swap : x = ", x, "y = ", y)Output:
Before Swap: x = 25 y = 30
After Swap : x = 30 y = 25
16. Write a program to repeat the string ‘‘GOOD MORNING” n times. Here n is an integer entered by the user.
Answer: – Showing Good Morning n times.
n = int(input("Enter Value of N : "))
print("GOOD MORNING" * n)Output:
Enter value of N : 3
GOOD MORNINGGOOD MORNINGGOOD MORNING
17. Write a program to find the average of 3 numbers.
Answer: – Program to find Average of 3 Numbers
n1 = int(input("Enter Number 1 : "))
n2 = int(input("Enter Number 2 : "))
n3 = int(input("Enter Number 3 : "))
average = (n1 + n2 + n3 ) / 3
print("Average of 3 Numbers : ", average)Output:
Enter Number 1 : 10
Enter Number 2 : 20
Enter Number 3 : 30
Average of 3 Numbers : 20
18. The volume of a sphere with radius r is 4/3πr3. Write a Python program to find the volume of spheres with radius 7cm, 12cm, 16cm, respectively.
Answer: Program to Calculate Volume of Sphere
import math
radius = int(input("Enter Radius (in cm) : "))
sphere_volume = 4/3 * math.pi * radius ** 3
print("Volume of Sphere with radius ", radius ,"is", sphere_volume,"cm^3")Output:
Enter Radius (in cm) : 7
Volume of Sphere with radius 7 is 1436.7550402417319 cm^3
Enter Radius (in cm) : 12
Volume of Sphere with radius 12 is 7238.229473870882 cm^3
Enter Radius (in cm) : 16
Volume of Sphere with radius 16 is 17157.284678805056 cm^3
19. Write a program that asks the user to enter one’s name and age. Print out a message addressed to the user that tells the user the year in which he/she will turn 100 years old.
Answer: – Program to find years in which you become 100 years old.
age = int(input("Enter Your Age : "))
name = input("Enter Your Name : ")
current_year = 2021
turn_to_hundread = current_year + 100 - age
print("He / She will turn 100 years old in year ", turn_to_hundread)Output:
Enter your Age : 21
Enter Your Name : Misha
He / She will turn 100 years old in year 2100
20. The formula E = mc2 states that the equivalent energy (E) can be calculated as the mass (m) multiplied by the speed of light (c = about 3×108 m/s) squared.
Write a program that accepts the mass of an object and determines its energy.
Answer:- Calculate Energy of an Object
mass = int(input("Enter mass of an object : "))
energy = mass * 3.0E8
print("Energy : ", energy)
Output:
Enter mass of an object : 156
Energy : 46800000000.0
21. Presume that a ladder is put upright against a wall. Let variables length and angle store the length of the ladder and the angle that it forms with the ground as it leans against the wall.
Write a Python program to compute the height reached by the ladder on the wall for the following values of length and angle:
a) 16 feet and 75 degrees (b) 20 feet and 0 degrees (c) 24 feet and 45 degrees (d) 24 feet and 80 degrees
Answer : – Python Program to Computer the Height reached by the ladder
import math
length = int(input("Enter the length of the ladder (feet) : "))
degrees = int(input("Enter the angle (degree) : "))
# Converting angle degree to radian
radian = math.radians(degrees)
# Calculating sin degree
sin_degree = math.sin(radian)
height = length * sin_degree
# rounding upto 2 decimal places
height = round(height, 2)
print("Length of Ladder : ", length, "feet")
print("Aligned Angle : ", degrees, "degree")
print("The height (of wall) reached by the ladder : ", height, "feet")Output:
(a) 16 feet and 75 degrees
Enter the length of the ladder (feet) : 16
Enter the angle (degree) : 75
Length of Ladder : 16 feet
Aligned Angle : 75 degree
The height (of wall) reached by the ladder : 15.45 feet
(b) 20 feet and 0 degrees
Enter the length of the ladder (feet) : 20
Enter the angle (degree) : 0
Length of Ladder : 20 feet
Aligned Angle : 0 degree
The height (of wall) reached by the ladder : 0.0 feet
(c) 24 feet and 45 degrees
Enter the length of the ladder (feet) : 24
Enter the angle (degree) : 45
Length of Ladder : 24 feet
Aligned Angle : 45 degree
The height (of wall) reached by the ladder : 16.97 feet
(d) 24 feet and 80 degrees
Enter the length of the ladder (feet) : 24
Enter the angle (degree) : 80
Length of Ladder : 24 feet
Aligned Angle : 80 degree
The height (of wall) reached by the ladder : 23.64 feet
Case Study Based Question
Schools use “Student Management Information System” (SMIS) to manage student related data. This system provides facilities for:
• Recording and maintaining personal details of students.
• Maintaining marks scored in assessments and computing results of students.
• Keeping track of student attendance, and
• Managing many other student-related data in the school.
Let us automate the same step by step.

Identify the personal details of students from your school identity card and write a program to accept these details for all students of your school and display them in this format.
print("Student Management Information System")
print("\t\t (SMIS)")
print(""40)
print("Enter the following details of Student")
name = input("Name : ")
rollno = input("Roll Number : ")
std = input("Class : ")
sec = input("Section : ")
address1 = input("Address 1 : ")
address2 = input("Address 2 : ")
city = input("City : ")
pin = input("Pin : ")
parents_contact = input("Parent's/Guardian's Contact No :")
print(""40)
print("Details you entered")
print("-"50) print("|"," "46,"|")
print("|","\t\tANJEEV SINGH ACADEMY\t\t","|")
print("|"," "46,"|") print("| Student Name: ", name,"\t\tRoll No. ",rollno) print("| Class : ",std, "\t\t\t Section", sec) print("| Address : ", 'address1') print("| \t", 'address2') print("|"," "46,"|")
print("| City :", city, "\t\tPin Code:",pin)
print("| Parent's / Guardian's Contact No:", parents_contact)
print("|"," "46,"|") print("-"50)







