Circle of Learning Logo CIRCLE OF LEARNING Excellence in Education
Class 11 Computer Science Chapter 5

NCERT Solutions for Class 11 Computer Science Chapter 5: Getting Started with Python

Class

Subject

Book

Chapter

Session

Questions covered

XI

Computer Science

Computer Science (NCERT)

5 – Getting Started with Python

2026-27

21 of 21

Chapter at a glance

Idea

Key point

Python

High-level, interpreted, case-sensitive, free and open-source language

Identifiers

Start with a letter or underscore; letters, digits, _ only; not a keyword; case-sensitive

Data types

int, float, complex, bool, str, list, tuple, set, dict, None

Mutable / immutable

list, dict, set are mutable; int, float, str, tuple are immutable

Operators

Arithmetic (+ - * / // % **), relational, logical (and or not), assignment (+= …), identity, membership

Precedence

** → unary - → * / // % → + - → relational → not → and → or; ** is right-associative

Input/output

input() always returns a string; print() displays output

Type conversion

Explicit: int(), float(), str(); implicit: int + float → float

Errors

Syntax error, logical error, runtime error (exception)

Exercise Questions

Q1

Which of the following identifier names are invalid and why?
(i) Serial_no. (ii) 1st_Room (iii) Hundred$ (iv) Total Marks (v) Total_Marks (vi) total-Marks (vii) _Percentage (viii) True

Answer

Answer

Identifier

Valid?

Reason

Serial_no.

Invalid

Contains a special character (.)

1st_Room

Invalid

Begins with a digit

Hundred$

Invalid

Contains a special character ($)

Total Marks

Invalid

Contains a space

Total_Marks

Valid

Letters and underscore only

total-Marks

Invalid

Contains a hyphen (−), which is an operator

_Percentage

Valid

May begin with an underscore

True

Invalid

It is a keyword (Boolean literal)

Invalid: Serial_no. (dot), 1st_Room (starts with digit), Hundred$ ($), Total Marks (space), total-Marks (hyphen), True (keyword). Valid: Total_Marks, _Percentage.

Q2

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

Answer

length, breadth = 10, 20 # a)
sum = (length + breadth) / 2 # b)
stationery = ['Paper', 'Gel Pen', 'Eraser'] # c)
first, middle, last = 'Mohandas', 'Karamchand', 'Gandhi' # d)
fullname = first + ' ' + middle + ' ' + last # e)

(Using sum as a variable hides the built-in sum() function; a name like avg is better practice.)

length, breadth = 10, 20; sum = (length + breadth)/2; stationery = [‘Paper’, ‘Gel Pen’, ‘Eraser’]; first, middle, last = ‘Mohandas’, ‘Karamchand’, ‘Gandhi’; fullname = first + ’ ’ + middle + ’ ’ + last

Q3

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

Answer

(20 + (-10)) < 12 # a) 10 < 12 → True
not (num3 > 24) # or num3 <= 24 # b)
(num1 < 6.75 < num2) or (num2 < 6.75 < num1) # c)
first < middle < last # d)
len(Stationery) == 0 # or Stationery == [] # e)

Evaluation (taking num1 = 4, num2 = 8, num3 = 30, and the names from Q2):

1. True

  1. 30 > 24, so not True = False
    1. 4 < 6.75 < 8 → True
    2. ‘Mohandas’ < ‘Karamchand’? ‘M’ > ‘K’, so the first comparison is False → False
    3. Stationery = [‘Paper’, ‘Gel Pen’, ‘Eraser’] has 3 items → False
  1. 20 + (-10) < 12 → True; b) not num3 > 24; c) num1 < 6.75 < num2 (or the reverse); d) first < middle < last; e) len(Stationery) == 0 — evaluated values depend on the variables (shown above for sample values).
Q4

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

Answer

  1. 0 == (1 == 2) → (1 == 2) is False, and 0 == False is True.
  2. 2 + (3 == 4) + 5 == 7 → (3 == 4) is False (= 0), so 2 + 0 + 5 = 7 and 7 == 7 is True.
  3. (1 < -1) == (3 > 4) → False == False is True.
  1. 0 == (1 == 2) b) 2 + (3 == 4) + 5 == 7 c) (1 < -1) == (3 > 4)
Q5

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

Answer

  1. num2 = 4 + 1 = 5 is computed before num1 changes to 2. Output: 2 5
  2. The right side is evaluated first using old values: num1 = 6, num2 = 2 + 2 = 4. Output: 6 4
  3. The right side num1, num3 + 1 uses num3, which has not been defined yet → NameError: name ‘num3’ is not defined. Nothing is printed.
  1. 2 5 b) 6 4 c) Error — NameError, num3 is not defined.
Q6

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

Answer

Data

Type

Reason

a) Months in a year

int

Whole number (12)

b) Resident of Delhi or not

bool

Only two values: True / False

c) Mobile number

str

No arithmetic is done on it; may begin with 0 or +

d) Pocket money

float

May have a fractional part (rupees and paise)

e) Volume of a sphere

float

Uses π, gives a decimal value

f) Perimeter of a square

float

Side may be a decimal (int if sides are whole numbers)

g) Name of the student

str

Sequence of characters

h) Address of the student

str

Letters, digits and symbols

  1. int b) bool c) str d) float e) float f) float (or int) g) str h) str
Q7

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

Answer

Part

Working

Output

a

4 + (3 + 2)

9

b

4 ** 5

1024

c

num1 becomes 4 ** 5 = 1024; nothing is printed

(no output)

d

String concatenation

55

e

4.0 / 4.0

1.0

f

2 + 9 × 28 / 10 = 2 + 25.2

27.2

g

(24 // 4) // 2 = 6 // 2

3

h

10.0

i

‘3.14’ is not an integer literal

ValueError: invalid literal for int()

j

Case-sensitive comparison

False

k

True and True

True

l

10 + 24 = 34 ≠ (2 − 3 = −1) → True; 29 ≥ 3.22 → True

True

m

5 + 10 = 15 < 50 → True; 29 ≤ 29 → True

True

n

(0 < 6) is True, so or gives True

True

  1. 9 b) 1024 c) no output (num1 = 1024) d) 55 e) 1.0 f) 27.2 g) 3 h) 10.0 i) ValueError j) False k) True l) True m) True n) True
Q8

Categorise the following as syntax error, logical error or runtime error:
a) 25 / 0 b) num1 = 25; num2 = 0; num1/num2

Answer

Answer

Both statements are syntactically correct, so Python accepts them, but division by zero cannot be carried out when the statement executes. Python raises ZeroDivisionError while running — a runtime error in both cases. (In b) the program’s logic of allowing a zero divisor is also at fault, which a check like if num2 != 0 would prevent.)

  1. Runtime error (ZeroDivisionError) b) Runtime error (ZeroDivisionError)
Q9

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

Answer

A point is inside the circle if its distance from the centre is at most the radius: √(x² + y²) ≤ 10, i.e.

x**2 + y**2 <= 100

Point

x² + y²

Result

(0, 0)

0

True

(10, 10)

200

False

(6, 6)

72

True

(7, 8)

113

False

Expression: x2 + y2 <= 100. a) True b) False c) True d) False

Q10

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

Answer

c = float(input("Enter temperature in Celsius: "))
f = c * 9 / 5 + 32
print("Temperature in Fahrenheit:", f)

  • Boiling point: 100 × 9/5 + 32 = 180 + 32 = 212 °F
  • Freezing point: 0 × 9/5 + 32 = 32 °F

f = c × 9/5 + 32; boiling point = 212 °F, freezing point = 32 °F.

Q11

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

Answer

P = float(input("Enter principal: "))
R = float(input("Enter rate of interest (% per annum): "))
T = float(input("Enter time (years): "))
SI = (P * R * T) / 100
amount = P + SI
print("Simple Interest =", SI)
print("Amount payable =", amount)

Sample run: P = 10000, R = 5, T = 2 → SI = 1000.0, Amount = 11000.0

SI = P × R × T / 100 and amount = P + SI (e.g. 10000, 5 %, 2 years → ₹ 11000).

Q12

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

Answer

x = float(input("Days taken by A: "))
y = float(input("Days taken by B: "))
z = float(input("Days taken by C: "))
days = (x * y * z) / (x * y + y * z + x * z)
print("Days needed together:", days)

Sample run: x = 10, y = 15, z = 30 → 4500 / (150 + 450 + 300) = 5.0 days

days = xyz / (xy + yz + xz); e.g. 10, 15, 30 days → 5 days together.

Q13

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

Answer

Answer

a = int(input("Enter first integer: "))
b = int(input("Enter second integer: "))
print("Sum =", a + b)
print("Difference =", a - b)
print("Product =", a * b)
print("Division =", a / b)
print("Floor division =", a // b)
print("Remainder =", a % b)
print("Exponent =", a ** b)

Sample run: a = 17, b = 5 → 22, 12, 85, 3.4, 3, 2, 1419857

Read two integers and print a + b, a − b, a × b, a / b, a // b, a % b and a ** b.

Q14

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

Answer

Answer

a = int(input("Enter a: "))
b = int(input("Enter b: "))
temp = a
a = b
b = temp
print("After swapping: a =", a, "b =", b)

Sample run: a = 5, b = 9 → a = 9, b = 5

temp = a; a = b; b = temp.

Q15

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

Answer

Answer

a = int(input("Enter a: "))
b = int(input("Enter b: "))
a = a + b
b = a - b
a = a - b
print("After swapping: a =", a, "b =", b)

Sample run: a = 5, b = 9 → a = 14, b = 5, a = 9. In Python this can also be written simply as a, b = b, a.

a = a + b; b = a − b; a = a − b (or a, b = b, a).

Q16

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

Answer

Answer

n = int(input("Enter n: "))
print("GOOD MORNING " * n)

The * operator repeats a string. Sample run: n = 3 → GOOD MORNING GOOD MORNING GOOD MORNING

print(“GOOD MORNING” * n) — string repetition with *.

Q17

Write a program to find average of three numbers.

Answer

Answer

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
avg = (a + b + c) / 3
print("Average =", avg)

Sample run: 10, 20, 30 → Average = 20.0

avg = (a + b + c) / 3.

Q18

The volume of a sphere with radius r is 4/3πr³. Write a Python program to find the volume of spheres with radius 7cm, 12cm, 16cm, respectively.

Answer

Answer

import math
for r in (7, 12, 16):
volume = 4 / 3 * math.pi * r ** 3
print("Radius", r, "cm: volume =", round(volume, 2), "cubic cm")

Output:

Radius 7 cm: volume = 1436.76 cubic cm
Radius 12 cm: volume = 7238.23 cubic cm
Radius 16 cm: volume = 17157.28 cubic cm

Volumes ≈ 1436.76 cm³, 7238.23 cm³ and 17157.28 cm³.

Q19

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

Answer

import datetime
name = input("Enter your name: ")
age = int(input("Enter your age: "))
current_year = datetime.date.today().year
year100 = current_year + (100 - age)
print("Hello", name + "! You will turn 100 years old in the year", year100)

Sample run (in 2026): name = Riya, age = 16 → Hello Riya! You will turn 100 years old in the year 2110

year = current year + (100 − age); e.g. age 16 in 2026 → 2110.

Q20

The formula E = mc² states that the equivalent energy (E) can be calculated as the mass (m) multiplied by the speed of light (c = about 3×10⁸ m/s) squared. Write a program that accepts the mass of an object and determines its energy.

Answer

Answer

m = float(input("Enter mass in kg: "))
c = 3 * 10 ** 8
E = m * c ** 2
print("Energy =", E, "joules")

Sample run: m = 2 kg → E = 2 × 9 × 10¹⁶ = 1.8 × 10¹⁷ J (printed as 180000000000000000.0).

E = m × (3 × 10⁸)²; e.g. 2 kg → 1.8 × 10¹⁷ J.

Q21

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

Answer

Formula: height = length × sin(angle). math.sin() needs the angle in radians, so convert with math.radians().

import math
length = float(input("Enter length of ladder (feet): "))
angle = float(input("Enter angle with ground (degrees): "))
height = length * math.sin(math.radians(angle))
print("Height reached =", round(height, 2), "feet")

Length

Angle

Height

16 ft

75°

15.45 ft

20 ft

0°

0.0 ft (ladder lies on the ground)

24 ft

45°

16.97 ft

24 ft

80°

23.64 ft

height = length × sin(angle): a) 15.45 ft b) 0 ft c) 16.97 ft d) 23.64 ft

Case study (SMIS): accept and display student details

n = int(input("Number of students: "))
for i in range(n):
name = input("Name: ")
admn = input("Admission number: ")
cls = input("Class and section: ")
dob = input("Date of birth: ")
father = input("Father's name: ")
phone = input("Contact number: ")
address = input("Address: ")
print("-" * 40)
print("Name:", name, "| Admission No.:", admn, "| Class:", cls)
print("DOB:", dob, "| Father:", father, "| Phone:", phone)
print("Address:", address)
print("-" * 40)

Topic checklist

  • ☒ Identifiers, data types and assignment (Q1, 2, 6)
  • ☒ Expressions, operators and precedence (Q3, 4, 7, 9)
  • ☒ Errors (Q5c, 7i, 8)
  • ☒ Simple programs (Q10–21)

Total questions answered: 21 of 21

Frequently Asked Questions

What do these NCERT solutions for Class 11 Computer Science Chapter 5 (Getting Started with Python) cover?

All 21 questions from the latest NCERT textbook for this chapter are answered step by step, organised as Exercise Questions.

Are these solutions based on the new NCERT syllabus?

Yes. The answers follow the current NCERT textbook for Class 11 Computer Science and the latest CBSE syllabus, so the question numbers and wording match the book you use in class.

How should I use these solutions to prepare for exams?

Attempt each question on your own first, then compare your working with the answer here. Note the steps or keywords you missed, and revise the chapter notes before taking a chapter-wise MCQ test to check your understanding.

Are the NCERT solutions for Class 11 Computer Science Chapter 5 (Getting Started with Python) free?

Yes. All Circle of Learning NCERT solutions and chapter notes are free to read online, with no sign-up needed.