Skip to main content
Chapter 5 of 11
NCERT Solutions

Getting Started with Python — NCERT Solutions

CBSE · Class 11 · Computer Science

NCERT Solutions for Getting Started with Python, CBSE Class 11 Computer Science: 22 textbook questions solved step by step.

50 questions74 flashcards2 formulas & key relations5 concepts

Interactive on Super Tutor

Studying Getting Started with Python? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for NCERT solutions and more.

Free trial, no card needed.

22 Questions Solved · 1 Section

The first 11 solutions are open to read. The other 11 are free with a Super Tutor account.

Exercise — Getting Started with Python

1Which 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
Show solution

Rules for valid Python identifiers:

  • Must begin with a letter (A–Z or a–z) or an underscore (_).
  • Can contain letters, digits (0–9), and underscores only.
  • Cannot be a Python keyword.
  • No spaces or special characters allowed.

i. Serial_no. — Invalid. Contains a dot (.), which is not allowed in an identifier.

ii. 1st_Room — Invalid. Starts with a digit (1), which is not permitted.

**iii. Hundred∗∗—∗∗Invalid∗∗.Containsaspecialcharacter(** — **Invalid**. Contains a special character (), which is not allowed.

iv. Total Marks — Invalid. Contains a space, which is not allowed.

v. Total_Marks — Valid. Starts with a letter and contains only letters and an underscore.

vi. total-Marks — Invalid. Contains a hyphen (-), which is not allowed (it is interpreted as the minus operator).

vii. Percentage — Valid. Starts with a letter and contains only letters.

viii. True — Invalid. True is a reserved keyword in Python and cannot be used as an identifier.

2Write 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.
Show solution

a) Assign 10 to length and 20 to breadth:
length, breadth=10,20\text{length, breadth} = 10, 20

length, breadth = 10, 20

b) Assign the average of length and breadth to sum:
sum=(length+breadth)/2\text{sum} = (\text{length} + \text{breadth}) / 2

sum = (length + breadth) / 2

c) Assign a list to stationery:

stationery = ['Paper', 'Gel Pen', 'Eraser']

d) Assign strings to first, middle, last:

first, middle, last = 'Mohandas', 'Karamchand', 'Gandhi'

e) Concatenate with spaces to form fullname:

fullname = first + ' ' + middle + ' ' + last

This gives fullname = 'Mohandas Karamchand Gandhi'.

3Write 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.
Show solution

a) The sum of 20 and -10 is less than 12:

(20 + (-10)) < 12

Evaluation: 20+(−10)=1020 + (-10) = 10, and 10<1210 < 12 is True.

b) num3 is not more than 24:

num3 <= 24

("Not more than" means less than or equal to.)

c) 6.75 is between the values of num1 and num2 (assuming num1 < num2):

num1 < 6.75 < num2

or equivalently:

(num1 < 6.75) and (6.75 < num2)

d) The string middle is larger than first and smaller than last (comparing variable values, not the literal strings):

(middle > first) and (middle < last)

e) List stationery is empty:

stationery == []

or equivalently:

len(stationery) == 0
4Add 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
Show solution

a) Original: 0==1==20 == 1 == 2 (evaluates to False)

Add parentheses:

0 == (1 == 2)

Evaluation: (1==2)(1 == 2) is False, which equals 0 in Python. So 0==False0 == \text{False} is 0==00 == 0 which is True. ✓

b) Original: 2+3==4+5==72 + 3 == 4 + 5 == 7 (evaluates to False)

Add parentheses:

2 + 3 == (4 + 5 == 7)

Evaluation: (4+5==7)(4 + 5 == 7) → (9==7)(9 == 7) → False → 00. Then 2+3==02 + 3 == 0 → 5==05 == 0 → False.

Alternative:

(2 + 3 == 4) + 5 == 7

Evaluation: (2+3==4)(2+3==4) → False → 00. Then 0+5==70 + 5 == 7 → 5==75 == 7 → False.

Best valid answer:

2 + (3 == 4 + 5) == 2

Evaluation: (3==4+5)(3 == 4+5) → (3==9)(3==9) → False → 00. Then 2+0==22 + 0 == 2 → 2==22 == 2 → True. ✓

c) Original: 1<−1==3>41 < -1 == 3 > 4 (evaluates to False)

Add parentheses:

1 < (-1 == 3) > 4

Evaluation: (−1==3)(-1 == 3) → False → 00. Then 1<01 < 0 → False. Not True.

Alternative:

(1 < -1) == (3 > 4)

Evaluation: (1<−1)(1 < -1) → False; (3>4)(3 > 4) → False. So False == False → True. ✓

5Write 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)
Show solution

a)

num1 = 4
num2 = num1 + 1   # num2 = 4 + 1 = 5
num1 = 2          # num1 is reassigned to 2
print(num1, num2)

Output: 2 5


b)

num1, num2 = 2, 6
num1, num2 = num2, num1 + 2
# Right-hand side is evaluated first:
# num2 = 6, num1 + 2 = 2 + 2 = 4
# So num1 = 6, num2 = 4
print(num1, num2)

Output: 6 4


c)

num1, num2 = 2, 3
num3, num2 = num1, num3 + 1

Here, num3 is used on the right-hand side (num3 + 1) before it has been assigned any value. This will raise a NameError: name 'num3' is not defined.

Output: NameError: name 'num3' is not defined

6Which 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
Show solution

a) Number of months in a year:
Data type: int (Integer)
Reason: The number of months is a whole number (12). It has no fractional part.

b) Resident of Delhi or not:
Data type: bool (Boolean)
Reason: This is a yes/no (True/False) condition — either the person is a resident or not.

c) Mobile number:
Data type: str (String)
Reason: Although a mobile number consists of digits, no arithmetic operations are performed on it. It may also contain a leading zero or a '+' prefix (e.g., +91...), so it is best stored as a string.

d) Pocket money:
Data type: float (Floating point)
Reason: Pocket money can include paise (decimal values), e.g., ₹150.50, so a float is appropriate.

e) Volume of a sphere:
Data type: float (Floating point)
Reason: Volume involves π\pi and fractional values, e.g., 43πr3\frac{4}{3}\pi r^3, which results in a decimal number.

f) Perimeter of a square:
Data type: float (Floating point)
Reason: The side length may be a decimal value, making the perimeter (4×side4 \times \text{side}) a float. Even if integer, float is safer for general use.

g) Name of the student:
Data type: str (String)
Reason: A name is a sequence of alphabetic characters.

h) Address of the student:
Data type: str (String)
Reason: An address is a combination of letters, digits, and special characters, best represented as a string.

7Give 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)))
Show solution

Given: num1 = 4, num2 = 3, num3 = 2

a)

num1 += num2 + num3
# num1 = 4 + (3 + 2) = 4 + 5 = 9
print(num1)

Output: 9


b)

num1 = num1 ** (num2 + num3)
# num1 = 4 ** (3 + 2) = 4 ** 5 = 1024
print(num1)

Output: 1024


c)

num1 **= num2 + num3
# num1 = 4 ** (3 + 2) = 4 ** 5 = 1024

(No print statement, so no output. num1 becomes 1024.)


d)

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

String concatenation: '5' + '5' = '55'
Output: 55


e)

print(4.00 / (2.0 + 2.0))
# = 4.00 / 4.0 = 1.0

Output: 1.0


f)

num1 = 2 + 9 * ((3 * 12) - 8) / 10
# Step 1: 3 * 12 = 36
# Step 2: 36 - 8 = 28
# Step 3: 9 * 28 = 252
# Step 4: 252 / 10 = 25.2
# Step 5: 2 + 25.2 = 27.2
print(num1)

Output: 27.2


g)

num1 = 24 // 4 // 2
# Left to right: 24 // 4 = 6, then 6 // 2 = 3
print(num1)

Output: 3


h)

num1 = float(10)
print(num1)

Converts integer 10 to float.
Output: 10.0


i)

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

int() cannot directly convert a string containing a decimal point. This raises a ValueError: invalid literal for int() with base 10: '3.14'.
Output: ValueError


j)

print('Bye' == 'BYE')

Python string comparison is case-sensitive. 'Bye' ≠ 'BYE'.
Output: False


k)

print(10 != 9 and 20 >= 20)
# 10 != 9 → True
# 20 >= 20 → True
# True and True → True

Output: True


l)

print(10 + 6 * 2 ** 2 != 9 // 4 - 3 and 29 >= 29 / 9)
# Step 1: 2 ** 2 = 4
# Step 2: 6 * 4 = 24
# Step 3: 10 + 24 = 34
# Step 4: 9 // 4 = 2
# Step 5: 2 - 3 = -1
# Step 6: 34 != -1 → True
# Step 7: 29 / 9 ≈ 3.222
# Step 8: 29 >= 3.222 → True
# Step 9: True and True → True

Output: True


m)

print(5 % 10 + 10 < 50 and 29 <= 29)
# Step 1: 5 % 10 = 5
# Step 2: 5 + 10 = 15
# Step 3: 15 < 50 → True
# Step 4: 29 <= 29 → True
# Step 5: True and True → True

Output: True


n)

print((0 < 6) or (not(10 == 6) and (10 < 0)))
# Step 1: 0 < 6 → True
# Since first operand of 'or' is True, result is True (short-circuit)
# (The second part: not(10==6) → not False → True; 10<0 → False; True and False → False)
# True or False → True

Output: True

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

a) 25 / 0

Category: Runtime Error

Reason: The expression is syntactically correct (Python can parse it), but when Python attempts to execute the division, it encounters division by zero, which is mathematically undefined. Python raises a ZeroDivisionError at runtime.


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

Category: Runtime Error

Reason: The syntax is correct and the variables are properly assigned. However, when the expression num1/num2 is evaluated at runtime, num2 is 0, causing a ZeroDivisionError. The error occurs during execution, not during parsing.

9A 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)
Show solution

Concept: A point (x,y)(x, y) lies within or on a circle of radius rr centred at the origin if:
x2+y2≤r2x^2 + y^2 \leq r^2
Here, r=10r = 10, so the condition is x2+y2≤100x^2 + y^2 \leq 100.

Python Expression:

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

Evaluation:

a) (0, 0):
02+02=0≤100⇒True0^2 + 0^2 = 0 \leq 100 \Rightarrow \textbf{True}
The dart hits the centre of the board.

b) (10, 10):
102+102=100+100=200≤100⇒False10^2 + 10^2 = 100 + 100 = 200 \leq 100 \Rightarrow \textbf{False}
The dart misses the board.

c) (6, 6):
62+62=36+36=72≤100⇒True6^2 + 6^2 = 36 + 36 = 72 \leq 100 \Rightarrow \textbf{True}
The dart hits the board.

d) (7, 8):
72+82=49+64=113≤100⇒False7^2 + 8^2 = 49 + 64 = 113 \leq 100 \Rightarrow \textbf{False}
The dart misses the board.

10Write a Python program to convert temperature in degree Celsius to degree Fahrenheit. If water boils at 100 degree C and freezes at 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)
Show solution

Formula: T(°F)=T(°C)×95+32T(°F) = T(°C) \times \dfrac{9}{5} + 32

Program:

# Program to convert Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit =", fahrenheit)

Verification:

Boiling point (100°C):
F=100×95+32=180+32=212°FF = 100 \times \frac{9}{5} + 32 = 180 + 32 = 212°F

Freezing point (0°C):
F=0×95+32=0+32=32°FF = 0 \times \frac{9}{5} + 32 = 0 + 32 = 32°F

Output:

  • Boiling point of water = 212.0 °F
  • Freezing point of water = 32.0 °F
11Write 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 × R × T) / 100. Amount payable = Principal + SI. P, R and T are given as input to the program.Show solution

Formula:
SI=P×R×T100SI = \frac{P \times R \times T}{100}
Amount=P+SI\text{Amount} = P + SI

Program:

# Program to calculate Simple Interest and Amount Payable
P = float(input("Enter Principal (P): "))
R = float(input("Enter Rate of Interest (R) in % per annum: "))
T = float(input("Enter Time (T) in years: "))

SI = (P * R * T) / 100
Amount = P + SI

print("Simple Interest =", SI)
print("Amount Payable =", Amount)

Sample Run:

Enter Principal (P): 1000
Enter Rate of Interest (R) in % per annum: 5
Enter Time (T) in years: 2
Simple Interest = 100.0
Amount Payable = 1100.0
12Write 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.

Free with a Super Tutor account

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

Free with a Super Tutor account

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

Free with a Super Tutor account

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

Free with a Super Tutor account

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

Free with a Super Tutor account

17Write a program to find average of three numbers.

Free with a Super Tutor account

18The 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.

Free with a Super Tutor account

19Write 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.

Free with a Super Tutor account

20The 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.

Free with a Super Tutor account

21Presume 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

Free with a Super Tutor account

Case StudySchools use 'Student Management Information System' (SMIS) to manage student-related data. 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 the given format (Name of School, Student Name, Roll No, Class, Section, Address, City, Pin Code, Parent's/Guardian's Contact No).

Free with a Super Tutor account

11 more solved questions in Getting Started with Python

They are free with a Super Tutor account, along with practice quizzes and flashcards for this chapter. Free to start, no card needed.

Frequently Asked Questions

What are the important topics in Getting Started with Python for CBSE Class 11 Computer Science?
Key topics in Getting Started with Python include Introduction to Python, Identifiers, Variables, and Comments, Everything is an Object and id(), Data Types in Python. Study these first, then practise questions on each for Class 11 exams.
Are these NCERT Solutions for Getting Started with Python free?
The first 11 of the 22 solutions on this page are open to read. The other 11 are free with a Super Tutor account — signing up is free and needs no card.
How should I revise Getting Started with Python for Class 11 exams?
Learn the core ideas first, then work through the 50 practice questions on Getting Started with Python. Revise definitions regularly and use flashcards for quick recall before the exam.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Getting Started with Python chapter — start free.

Quizzes, flashcards, an AI doubt solver and a study plan for CBSE Class 11 Computer Science. Free to start, no card needed.