NCERT Solution of Class 11 Informatics Practices
Chapter 3 – Brief Overview of Python
1. 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
Answer: – Valid Identifiers are :
(e) Total_Marks and (g) _Percentage
Invalids Identifiers are :
(a) Serial_no. : Special Symbol . (dot) is not allowed in identifier name
(b) 1st_Room : Identifier name can not start with digit.
(c) Hundred$ : Special Symbol $ is not allowed in identifier name
(d) Total Marks : Space is not allowed in identifier name
(f) total-Marks : Special Symbol – (hyphen) is not allowed in identifier name
(h) True : True is a keyword, and Keyword is not allowed in identifier name
2. Write the corresponding Python assignment statements:
a) Assign 10 to variable length and 20 to variable breadth.
Answer: – length = 10
breadth = 10
b) Assign the average of values of variables length and breadth to a variable sum.
Answer: – sum = (length + breadth) / 2
c) Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.
Answer: – stationery = [‘Paper’, ‘Gel Pen’, ‘Eraser’]
d) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.
Answer: – first , middle, last = ‘Mohandas’, ‘Karamchand’, ‘Gandhi’
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: – fullname = first + ‘ ‘ + middle + ‘ ‘ + last
3. 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: –
a) Number of months in a year: integer, number of month is a positive numeric value.
b) Resident of Delhi or not : Boolean, Resident of Delhi or not can be store as True or False
You can store it as String also, if you want to store value as “Yes” or “No”
c) Mobile number: String, because a mobile number not only contains number, it contain symbols like +, – and space also.
d) Pocket money: float, money can be stored as decimal number.
e) Volume of a sphere : float or integer, it is a numeric value. float is most appropriate.
f) Perimeter of a square: float, it is a numeric value.
g) Name of the student: String, Name can contain alphabet and space.
h) Address of the student: String, Address can contain alphanumeric value
4. Give the output of the following when num1 = 4, num2 = 3, num3 = 2
a) num1 += num2 + num3
Answer: – Value of num1 = 4 + (3 + 2) = 9
b) print (num1)
Answer: – 9
c) num1 = num1 ** (num2 + num3)
Answer: – num1 = 4 ** (3+2) = 4 ** 5 = 1024
d) print (num1)
Answer: – 1024
e) num1 *= num2 + c
Answer: – NameError : Undefined symbol ‘c’
f) num1 = ‘5’ + ‘5’
Answer: – ’55’
g) print(num1)
Answer: – 55
h) print(4.00/(2.0+2.0))
Answer: – 1.0
i) num1 = 2 + 9 * (( 3 * 12) – 8)/10
Answer: – 2 + 9 * (36 – 8) / 10 = 2 + 9 * 28 / 10 = 2 + 25.2 = 27.2
j) print(num1)
Answer: – 27.2
k) num1 = float(10)
Answer: – 10.0
l) print (num1)
Answer: – 10.0
m) num1 = int(‘3.14’)
Answer: – ValueError: invalid literal for int() with base 10: ‘3.14’
It should be like num1 = int(float(‘3.14’))
n) print (num1)
Answer: – 3.14 , if statement given in (m) is correct and executed properly.
o) print(10 != 9 and 20 >= 20)
Answer:- True
p) print(5 % 10 + 10 < 50 and 29 <= 29)
Answer: – True
5. Categorise the following as syntax error, logical error or runtime error:
a) 25 / 0
Answer: – Run Time Error : Division by Zero
b) num1 = 25; num2 = 0; num1/num2
Answer: – Run Time Error : Division by Zero
6. 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.
Answer: – Program to calculate Simple Interest
p = float(input("Enter Principal Amount : ")) r = int(input("Enter rate of interest : ")) t = int(input("Enter time : ")) si = (p * r * t) / 100 print("Simple Interest Rs. ", si) amount_payable = p + si print("Amount Payable Rs.", amount_payable)
7. Write a program to repeat the string ‘‘GOOD MORNING” n times. Here n is an integer entered by the user.
Answer: – Showing Good Morning n times.
n = int(input("Enter Value of N : ")) for a in range(n): print("GOOD MORNING")
Method – 2 : Showing Good Morning n times
n = int(input("Enter Value of N : ")) print("GOOD MORNING" * n)
8. Write a program to find the average of 3 numbers.
Answer: – Program to find Average of 3 Numbers
n1 = int(input("Enter Number 1 : ")) n2 = int(input("Enter Number 2 : ")) n3 = int(input("Enter Number 3 : ")) average = (n1 + n2 + n3 ) / 3 print("Average of 3 Numbers : ", average)
9. Write a program that asks the user to enter one’s name and age. Print out a message addressed to the user that tells the user the year in which he/she will turn 100 years old.
Answer: – Program to find years in which you become 100 years old.
age = int(input("Enter Your Age : ")) name = input("Enter Your Name : ") current_year = 2021 turn_to_hundread = current_year + 100 - age print("He / She will turn 100 years old in year ", turn_to_hundread)
10. What is the difference between else and elif construct of if statement?
Answer: – else statement does not allow to check the condition, while elif allow to check the condition. elif is use to handle the multiple situations.
11. Find the output of the following program segments:
a) for i in range(20,30,2): print(i)
Answer: – Output:
20
22
26
28
11. Find the output of the following program segments:
b) country = 'INDIA' for i in country: print (i)
Answer: – Output:
I
N
D
I
A
11. Find the output of the following program segments:
c) i = 0; sum = 0 while i < 9: if i % 4 == 0: sum = sum + i i = i + 2 print (sum)
Answer: – Output:
12
Case Study Based Question
Schools use “Student Management Information System” (SMIS) to manage student related data. This system provides facilities for:
• Recording and maintaining personal details of students.
• Maintaining marks scored in assessments and computing results of students.
• Keeping track of student attendance, and
• Managing many other student-related data in the school.
Let us automate the same step by step.
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 this format.
print("Student Management Information System") print("\t\t (SMIS)") print(""40) print("Enter the following details of Student") name = input("Name : ") rollno = input("Roll Number : ") std = input("Class : ") sec = input("Section : ") address1 = input("Address 1 : ") address2 = input("Address 2 : ") city = input("City : ") pin = input("Pin : ") parents_contact = input("Parent's/Guardian's Contact No :") print(""40) print("Details you entered") print("-"50) print("|"," "46,"|") print("|","\t\tANJEEV SINGH ACADEMY\t\t","|") print("|"," "46,"|") print("| Student Name: ", name,"\t\tRoll No. ",rollno) print("| Class : ",std, "\t\t\t Section", sec) print("| Address : ", 'address1') print("| \t", 'address2') print("|"," "46,"|") print("| City :", city, "\t\tPin Code:",pin) print("| Parent's / Guardian's Contact No:", parents_contact) print("|"," "46,"|") print("-"50)