CBSE Class 11 Getting Started with Python Solutions

Share with others

Teachers and Examiners (CBSESkillEduction) collaborated to create the CBSE Class 11 Getting Started with Python Solutions. All the important Information are taken from the NCERT Textbook Computer Science (083) class 11.

CBSE Class 11 Getting Started with Python Solutions

1. Which of the following identifier names are invalid and why?

i.Serial_no.v.Total_Marks
ii.1st_Roomvi.total-Marks
iii.Hundred$vii._Percentage
iv.Total Marksviii.True


Answer –

Invalid IdentifierValid/ InvalidWhy
Serial_no.InvalidPython Identifier can contain underscore (_), but (.) is not allowed.
1st_RoomInvalidIdentifier cannot start with a number.
Hundred$InvalidPython Identifier can contain underscore but other special character like ( !, @, #, $, % etc. ) are not allowed.
Total_MarksValidUnderscore (_) is allowed in Python identifier.
total-MarksInvalid(-) hyphen is not allowed in Python identifier.
_PercentageValid( _ ) Underscore is allowed in Python identifier.
TrueInvalidKeyword is not allowed as Identifier

2. Write the corresponding Python assignment statements:
a) Assign 10 to variable length and 20 to variable breadth.
b) Assign the average of values of variables length and breadth to a variable sum.
c) Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.
d) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.
e) Assign the concatenated value of string variables first, middle and last to variable fullname. Make sure to incorporate blank spaces appropriately between different parts of names.

Answer –

  • a) length = 10, breadth = 20 or length, breadth = 10, 20
  • b) sum=(length + breadth) / 2
  • c) stationery = [ ‘Paper’ , ‘Gel Pen’ , ‘Eraser’ ]
  • d) first = ‘Mohandas’ , middle = ‘Karamchand’ , last = ‘Gandhi’
  • e) fullname = first + ” ” + middle + ” ” + last
# a) Assign 10 to length and 20 to breadth
length = 10
breadth = 20 

# b) Calculate the average of length and breadth
avg = (length + breadth) / 2 

# c) Create a list of stationery items
stationery = ["Paper", "Gel Pen", "Eraser"]

# d) Assign first, middle, and last names
first = "Mohandas"
middle = "Karamchand"
last = "Gandhi"

# e) Concatenate first, middle, and last names with spaces
fullname = first + " " + middle + " " + last

# Printing to verify
print("Full Name:", fullname)
print("Stationery Items:", stationery)
print("Average:", avg)

3. Write logical expressions corresponding to the following statements in Python and evaluate the expressions (assuming variables num1, num2, num3, first, middle, last are already having meaningful values):
a) The sum of 20 and –10 is less than 12.
b) num3 is not more than 24.
c) 6.75 is between the values of integers num1 and num2.
d) The string ‘middle’ is larger than the string ‘first’ and smaller than the string ‘last’.
e) List Stationery is empty.

Answer –

  • a) ( 20 + ( – 10 )) < 12
  • b) num3 <= 24 or not(num3 > 24)
  • c) (6.75 >= num1) and (6.75 <= num2)
  • d) (middle > first) and (middle < last)
  • e) len(Stationery) == 0
# a) The sum of 20 and –10 is less than 12.
result_a = (20 + (-10)) < 12

# b) num3 is not more than 24.
result_b = num3 <= 24

# c) 6.75 is between the values of integers num1 and num2.
result_c = num1 <= 6.75 <= num2

# d) The string ‘middle’ is larger than the string ‘first’ and smaller than the string ‘last’.
result_d = (middle > first) and (middle < last)

# e) List Stationery is empty.
result_e = not Stationery 

# Print results
print(result_a, result_b, result_c, result_d, result_e)

4. Add a pair of parentheses to each expression so that it evaluates to True.
a) 0 == 1 == 2
b) 2 + 3 == 4 + 5 == 7
c) 1 < -1 == 3 > 4

Answer –

  • a) ( 0 == (1==2))
  • b) (2 + (3 == 4) + 5) == 7
  • c) (1 < -1) == (3 > 4 )
# a) 0 == 1 == 2
result_a = (0 == (1 == 2)) 

# b) 2 + 3 == 4 + 5 == 7
result_b = ((2 + 3) == (4 + 5) == 7) 

# c) 1 < -1 == 3 > 4
result_c = ((1 < -1) == (3 > 4)) 

# Print results
print(result_a, result_b, result_c)

5. Write the output of the following:

a) 
num1 = 4
num2 = num1 + 1
num1 = 2
print (num1, num2)

b) 
num1, num2 = 2, 6
num1, num2 = num2, num1 + 2
print (num1, num2)

c) 
num1, num2 = 2, 3
num3, num2 = num1, num3 + 1
print (num1, num2, num3)

Answer –

  • a) 2, 5
  • b) 6, 4
  • c) NameError: name ‘num3’ is not defined

6. Which data type will be used to represent the following data values and why?

  • a) Number of months in a year
  • b) Resident of Delhi or not
  • c) Mobile number
  • d) Pocket money
  • e) Volume of a sphere
  • f) Perimeter of a square
  • g) Name of the student
  • h) Address of the student

Answer –

Data ValuesData TypeWhy
a) Number of months in a yearIntegerNumber can be store in Integer data type
b) Resident of Delhi or notBooleanThe result can be store in true or false
c) Mobile numberInteger/ StringYou can add mobile number in both data type
d) Pocket moneyFloatThe money can be calculated in the decimal point
e) Volume of a sphereFloatThe volume can be calculated in the decimal point
f) Perimeter of a squareFloatThe perimeter can be calculated in the decimal point
g) Name of the studentStringName contain characters
h) Address of the studentStringAddress contain characters, special symbol, numbers etc.


7. Give the output of the following when num1 = 4, num2 = 3, num3 = 2

a) 
num1 += num2 + num3
print (num1)

b) 
num1 = num1 ** (num2 + num3)
print (num1)

c) 
num1 **= num2 + num3

d) 
num1 = '5' + '5'
print(num1)

e) 
print(4.00/(2.0+2.0))

f) 
num1 = 2+9*((3*12)-8)/10
print(num1)

g) 
num1 = 24 // 4 // 2
print(num1)

h) 
num1 = float(10)
print (num1)

i) 
num1 = int('3.14')
print (num1)

j) 
print('Bye' == 'BYE')

k) 
print(10 != 9 and 20 >= 20)

l) 
print(10 + 6 * 2 ** 2 != 9//4 -3 and 29 >= 29/9)

m) 
print(5 % 10 + 10 < 50 and 29 <= 29)

n) 
print((0 < 6) or (not(10 == 6) and (10<0)))

Answer –

  • a) Output 9
  • b) Output 1024
  • c) Output 1024
  • d) Output 55
  • e) Output 1.0
  • f) Output 27.2
  • g) Output 3
  • h) Output 10.0
  • i) Error
  • j) Output False
  • k) Output True
  • l) Output True
  • m) Output True
  • n) Output True

8. Categories the following as syntax error, logical error or runtime error:

a) 25 / 0
b) num1 = 25; num2 = 0; num1/num2

Answer –

  • a) Error Type: Runtime Error (ZeroDivisionError)
  • b) Error Type: Runtime Error (ZeroDivisionError)

9. A dartboard of radius 10 units and the wall it is hanging on are represented using a two-dimensional coordinate system, with the board’s center at coordinate (0,0). Variables x and y store the x-coordinate and the y-coordinate of a dart that hits the dartboard. Write a Python expression using variables x and y that evaluates to True if the dart hits (is within) the dartboard, and then evaluate the expression for these dart coordinates:

  • a) (0,0)
  • b) (10,10)
  • c) (6, 6)
  • d) (7,8)

Answer –

  • a) True
  • b) False
  • c) True
  • d) False

10. Write a Python program to convert temperature in degree Celsius to degree Fahrenheit. If water boils at 100 degree C and freezes as 0 degree C, use the program to find out what is the boiling point and freezing point of water on the Fahrenheit scale.
(Hint: T(°F) = T(°C) × 9/5 + 32)

Answer –

# Define water boiling and freezing points in Celsius
boiling_celsius = 100
freezing_celsius = 0

# Convert temperatures to Fahrenheit
boiling_fahrenheit = boiling_celsius * (9/5) + 32
freezing_fahrenheit = freezing_celsius * (9/5) + 32

# Print results
print("Boiling temperature in Fahrenheit:", boiling_fahrenheit)
print("Freezing temperature in Fahrenheit:", freezing_fahrenheit)

Output:
Boiling temperature in Fahrenheit: 212.0
Freezing temperature in Fahrenheit: 32.0

11. Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate of interest = R% per annum and Time = T years. Then Simple Interest (SI) = (P x R x T)/ 100. Amount payable = Principal + SI. P, R and T are given as input to the program.

Answer –

p = float(input('Enter principal amount - '))
r = float(input('Enter the rate of interest - '))
t = float(input('Enter the time - '))
si = (p * r * t)/100
rs = si + p
print('Total amount - ',rs)

Output 
Enter principal amount - 5000
Enter the rate of interest - 6
Enter the time - 2
Total amount - 5600.0

12. Write a program to calculate in how many days a work will be completed by three persons A, B and C together. A, B, C take x days, y days and z days respectively to do the job alone. The formula to calculate the number of days if they work together is xyz/(xy + yz + xz) days where x, y, and z are given as input to the program.

Answer –

x = int(input('Number of days required to do the job alone by A - '))
y = int(input('Number of days required to do the job alone by B - '))
z = int(input('Number of days required to do the job alone by C - '))
calculate = (x * y * z) / (x*y + y*z + x*z)
days = round(calculate,2)
print('Total number of days to complete the work together by A, B & C - ', days)

Output 
Number of days required to do the job alone by A - 10
Number of days required to do the job alone by B - 15
Number of days required to do the job alone by C - 20
Total number of days to complete the work together by A, B & C - 4.62


13. Write a program to enter two integers and perform all arithmetic operations on them.

Answer –

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

print("\nResults:")
print("Addition:", num1 + num2)
print("Subtraction:", num1 - num2)
print("Multiplication:", num1 * num2)
print("Division:", num1 / num2) 
print("Modulus:", num1 % num2)
print("Floor Division:", num1 // num2)
print("Exponentiation:", num1 ** num2)

Output
Enter the first number: 7
Enter the second number: 4

Results:
Addition: 11
Subtraction: 3
Multiplication: 28
Division: 1.75
Modulus: 3
Floor Division: 1
Exponentiation: 2401


14. Write a program to swap two numbers using a third variable.

Answer –

num1 = int(input("Enter 1st Number "))
num2 = int(input("Enter 2nd Number "))
temp = num1
num1 = num2
num2 = temp
print("After Swap")
print("Value of num1 - ", num1)
print("Value of num2 - ", num2)

Output
Enter 1st Number 6
Enter 2nd Number 4
After Swap
Value of num1 - 4
Value of num2 - 6

15. Write a program to swap two numbers without using a third variable.

Answer –

num1 = int(input("Enter 1st Number "))
num2 = int(input("Enter 2nd Number "))
num1 = num1 + num2
num2 = num1 - num2
num1 = num1 - num2
print("After Swap")
print("Value of num1 - ", num1)
print("Value of num2 - ", num2)

Output
Enter 1st Number 6
Enter 2nd Number 4
After Swap
Value of num1 - 4
Value of num2 - 6

16. Write a program to repeat the string ‘‘GOOD MORNING” n times. Here ‘n’ is an integer entered by the user.

Answer –

str = "GOOD MORNING "
n = int(input("Enter the terms - "))

if n > 0:
    print(str * n) 
else:
    print("Enter a value greater than 0")


Output 
Enter the terms - 5
GOOD MORNING GOOD MORNING GOOD MORNING GOOD MORNING GOOD MORNING 

17. Write a program to find average of three numbers.

Answer –

a = 7
b = 8
c = 9
average = (a + b + c)/3
print("The average of a, b and c is ",average)

Output
The average of a, b and c is 8.0

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 –

import math 

r1 = 7
r2 = 12
r3 = 16

print("Volume of Sphere when radius is 7cm:", round((4/3 * math.pi * r1**3), 2))
print("Volume of Sphere when radius is 12cm:", round((4/3 * math.pi * r2**3), 2))
print("Volume of Sphere when radius is 16cm:", round((4/3 * math.pi * r3**3), 2))

Output:
Volume of Sphere when radius is 7cm: 1436.76
Volume of Sphere when radius is 12cm: 7238.23
Volume of Sphere when radius is 16cm: 17157.28

19. Write a program that asks the user to enter their name and age. Print a message addressed to the user that tells the user the year in which they will turn 100 years old.

Answer –

from datetime import datetime 

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

# Get current year dynamically
current_year = datetime.now().year

hundred_year = current_year + (100 - age)

print(f"Hello {name}! You will turn 100 years old in the year {hundred_year}.")

Output:
Enter your name: Rajesh
Enter your age: 22
Hello Rajesh! You will turn 100 years old in the year 2103.

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 –

mass = float(input("Enter the mass (in kg): "))

# Speed of light (m/s)
speed_of_light = 3 * 10**8

energy = mass * (speed_of_light ** 2)

print("Energy produced by the given mass is:", energy)

Output:
Enter the mass (in kg): 50
Energy produced by the given mass is: 4.5e+15

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 –

import math

length = float(input("Enter the length of the ladder (in feet): "))
angle = float(input("Enter the angle in degrees: "))

# Convert degrees to radians and compute height using sine function
radians = math.radians(angle)
height = round(length * math.sin(radians), 2)

print(f"Height reached by the ladder: {height} feet")

Output:

Ladder LengthAngleComputed Height
167515.45
2000.00
244516.97
248023.64

Computer Science Class 11 Questions and Answers

Disclaimer: We have taken an effort to provide you with the accurate handout of “CBSE Class 11 Getting Started with Python Solutions“. If you feel that there is any error or mistake, please contact me at anuraganand2017@gmail.com. The above CBSE study material present on our websites is for education purpose, not our copyrights. All the above content and Screenshot are taken from Computer Science Class 11 NCERT Textbook and CBSE Support Material which is present in CBSEACADEMIC website, This Textbook and Support Material are legally copyright by Central Board of Secondary Education. We are only providing a medium and helping the students to improve the performances in the examination. 

Images and content shown above are the property of individual organizations and are used here for reference purposes only.

For more information, refer to the official CBSE textbooks available at cbseacademic.nic.in


Share with others

Leave a Comment