Page 288 - Computer Science V2.0 Class 11
P. 288
(iii) if value == 10:
square = value*value
print("The square of ", value,"is",square)
else:
print("Wrong value entered")
Ans. (i) Incorrect case of keywords – if, elif and else
If value == 10: ------ > 'I' of keyword if is in upper case
square = value*value
(ii) The header is not terminated with a colon (:)
if value == 10 --- > colon missing
square = value*value
(iii) Not indenting the statements of if / else / elif blocks correctly
if value == 10:
square = value*value
print("The square of ", value,"is",square) --->Wrong indentation
else:
print("Wrong value entered") --->Wrong indentation
9. Rewrite the following code to make it executable by changing just one token.
if x = 10:
print(x)
elif:
print(x*x)
Ans. if x == 10:
print(x)
else:
print(x*x)
10. Find the output of the following code snippet for the following values of year provided by the user:
a. 2020 b. 2051 c. 2100
year = int(input('Enter the year of Christian Era'))
if year % 100 == 0:
if year % 400 == 0:
print('Leap Year')
elif(year % 4 == 0):
print('Leap Year')
else:
print('Not a Leap Year')
Ans. a. Leap Year
b. Not a Leap Year
c. No output will be produced
274 Touchpad Computer Science (Ver. 2.0)-XI

