NCERT Solution Chapter 3 Brief Overview of Python
SUMMARY : Brief Overview of Python
Python is an open-source, high level, interpreter based language that can be used for a multitude of
scientific and non-scientific computing purposes.
Comments are non-executable statements in a program.
An identifier is a user defined name given to a variable or a constant in a program.
Process of identifying and removing errors from a computer program is called debugging.
Trying to use a variable that has not been assigned a value gives an error.
There are several data types in Python โ integer, Boolean, float, complex, string, list, tuple, sets,
None and dictionary.
Operators are constructs that manipulate the value of operands. Operators may be unary or binary.
An expression is a combination of values, variables, and operators.
Python has input() function for taking user input.
Python has print() function to output data to a standard output device.
The if statement is used for decision making.
Looping allows sections of code to be executed repeatedly under some condition.
for statement can be used to iterate over a range of values or a sequence.
The statements within the body of for loop are executed till the range of values is exhausted.
NCERT Solution Chapter 3
Q1. Which of the following identifier names are invalid and why?
a) Serial_no.
b) 1st_Room
c) Hundred$
d) Total Marks
e) Total_Marks
f) total-Marks
g) _Percentage
h) True
Invalid Identifier Name Reason b) 1st_Room Identifier name can not start with number c) Hundred$ Special symbols not allowed in Identifier. d) Total Marks Spaces are not allowed in identifier name f) total-Marks Special symbols not allowed in Identifier except underscore h) True Keyword can not be used as identifier.
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.
breadth = 20 OR (we can also assign values in a single line) length , breadth = 10, 20 b) sum = (length + breadth)/2 c) stationery = [โPaperโ, โGel Penโ, โEraserโ] d) first, middle, last = โMohandasโ, โKaramchandโ, โGandhiโ e) fullname = first + ” ” + middle + ” ” + last
NCERT Solution Chapter 3
Q3. 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
Variable Name Data type Reason Number of months in a year int Number of month can only be integer Resident of Delhi or not Boolean To store YES or NO we need Boolean data type Mobile number int or String It is a collection of 10 – 12 digits where
no calculation is requiredPocket money float It could be any floating point number Volume of a sphere float It could be any floating point number Perimeter of a square float It could be any floating point number Name of the student String Name of student is a collection of characters Address of the student String Address is a combination of characters and numbers
NCERT Solution Chapter 3
Q4. Give the output of the following when num1 = 4, num2 =3, num3 = 2
a) num1 += num2 + num3
b) print (num1)
c) num1 = num1 ** (num2 + num3)
d) print (num1)
e) num1 *= num2 + c #Here c is not defined
f) num1 = ‘5’ + ‘5’
g) print(num1)
h) print(4.00/(2.0+2.0)) i) num1 = 2+9((3*12)-8)/10
j) print(num1)
k) num1 = float(10)
l) print (num1)
m) num1 = int(‘3.14’)
n) print (num1)
o) print(10 != 9 and 20 >= 20)
p) print(5 % 10 + 10 < 50 and 29 <= 29)
Ans. b) 9 d) 59049 g) 55 h) 1.0 j) 27.2 l) 10.0 n) 10.0 o) True p) True Statement e) will show error as here variable c is not defined
NCERT Solution Chapter 3
Q5. Categorise the following as syntax error, logical error or runtime error:
a) 25 / 0
b) num1 = 25; num2 = 0; num1/num2
b) ZeroDivisionError: division by zero
Q6. Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate = 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
Ans. P=float(input("Enter Principal")) R= float(input("Enter Rate of interest")) T= float(input("Enter Time")) SI = (P * R * T)/100 A = P + SI print("Amount to be paid is", A)
Q7. Write a program to repeat the string โโGOOD MORNINGโ n times. Here โnโ is an integer entered by the user.
n = int(input(“Enter how many times you want to repeat ?”))
print(“GOOD MORNING” * n)
NCERT Solution Chapter 3
Q8. Write a program to find average of three numbers.
num1 = int(input(“Enter First Number “))
num2 = int(input(“Enter Second Number “))
num3 = int(input(“Enter Third Number “))
avg = (num1 +num2 + num3)/3
print(“Average of three numbers is :”, avg)
Q9. 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.
nm = input(“Enter Your Name”)
age = int(input(“Enter Your age”))
yr = 2021 + (100 – age) #Taking 2021 as Current Year
print(nm,” :You will turn 100 in “,yr)
Q10. What is the difference between else and elif construct of if statement?
Many a times there are situations that require multiple conditions to be checked and it may lead to many alternatives. In such cases we can make a chain of conditions using elif. Syntax of elif is shown below:
if condition:
statement(s)
else:
statement(s)if condition :
statement
elif condition :
statement
elif condition :
statement
|
|
|
|
else :
statement
NCERT Solution Chapter 3
Q11. Find the output of the following program segments:
a)
for i in range(20,30,2):
print(i) 20
22
24
26
28
b)
country = 'INDIA'
for i in country:
print (i) I
N
D
I
A
c)
i = 0; sum = 0
while i < 9:
if i % 4 == 0:
sum = sum + i
i = i + 2
print (sum)
NCERT Solution Chapter 3
Disclaimer : I tried to give you the correct NCERT Solution Chapter 3 , but if you feel that there is/are mistakes in the “NCERT Solution Chapter 3“ given above, you can directly contact me at csiplearninghub@gmail.com.
NCERT Solution Chapter 3
Class 12 Computer Science Sample Paper 2020-2021.
Class 12 Computer Science Sample Paper Marking Scheme
Class 12 Computer Science Test Series








