NCERT Solution Chapter 3
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
Ans. Invalid Identifiers are :
Invalid Identifier Name Reason
Number of months in a
int Number of month can only be integer
year
Resident of Delhi or not Boolean To store YES or NO we need Boolean data type
b) 9
d) 59049
g) 55
h) 1.0
j) 27.2
l) 10.0
n) 10.0
o) True
p) True
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.
Ans
n = int(input(“Enter how many times you want to repeat ?”))
print(“GOOD MORNING” * n)
Q8. Write a program to find average of three numbers.
Ans.
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.
Q10. What is the difference between else and elif construct of if statement?
Ans. if..else statement allows us to write two alternative paths and the control condition determines
which path gets executed. If the condition is incorrect/False then else statement will execute. The
syntax for if..else statement is as follows.
if condition:
statement(s)
else:
statement(s)
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
elif condition :
statement
elif condition :
statement
|
|
|
|
else :
statement
Q11. Find the output of the following program segments:
a) for i in range(20,30,2):
print(i)
Ans.
20
22
24
26
28
b) country = 'INDIA'
for i in country:
print (i)
Ans.
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)
Ans. 12