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.
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.
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. TrueShow 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), 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, 20b) Assign the average of length and breadth to sum:
sum = (length + breadth) / 2c) 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 + ' ' + lastThis 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)) < 12Evaluation: , and 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 < num2or 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) == 04Add 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 > 4Show solution
a) Original: (evaluates to False)
Add parentheses:
0 == (1 == 2)Evaluation: is False, which equals 0 in Python. So is which is True. ✓
b) Original: (evaluates to False)
Add parentheses:
2 + 3 == (4 + 5 == 7)Evaluation: → → False → . Then → → False.
Alternative:
(2 + 3 == 4) + 5 == 7Evaluation: → False → . Then → → False.
Best valid answer:
2 + (3 == 4 + 5) == 2Evaluation: → → False → . Then → → True. ✓
c) Original: (evaluates to False)
Add parentheses:
1 < (-1 == 3) > 4Evaluation: → False → . Then → False. Not True.
Alternative:
(1 < -1) == (3 > 4)Evaluation: → False; → 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 + 1Here, 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 studentShow 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 and fractional values, e.g., , 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 () 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.0Output: 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 → TrueOutput: 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 → TrueOutput: 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 → TrueOutput: 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 → TrueOutput: True
8Categorise the following as syntax error, logical error or runtime error:
a) 25 / 0
b) num1 = 25; num2 = 0; num1/num2Show 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 lies within or on a circle of radius centred at the origin if:
Here, , so the condition is .
Python Expression:
(x**2 + y**2) <= 100Evaluation:
a) (0, 0):
The dart hits the centre of the board.
b) (10, 10):
The dart misses the board.
c) (6, 6):
The dart hits the board.
d) (7, 8):
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:
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):
Freezing point (0°C):
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:
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.0Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
Free with a Super Tutor account
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
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?
Are these NCERT Solutions for Getting Started with Python free?
How should I revise Getting Started with Python for Class 11 exams?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Getting Started with Python
Practice Quiz
Test yourself with a quick quiz
Important Questions
Exam-style questions with answers
Revision Notes
Key points for last-minute revision
Formula Sheet
The chapter's formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect
Study Plan
Step-by-step plan for this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
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.