Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 72 of 102
Marks: +1, -0
Observe the following code carefully and rewrite it after removing all syntactical errors. Underline all the corrections made.
def 1func():
a=input("Enter a number"))
if a>=33
print("Promoted to next class")
ELSE:
print("Repeat")
[CBSE 2024 Compartment]
Solution:  
Corrected code (corrections underlined):
def func1():
a=int(input("Enter a number"))
if a>=33:
print("Promoted to next class")
else:
print("Repeat")
Errors corrected:
1. 1func: an identifier cannot start with a digit; renamed func1 (any valid name).
2. input("Enter a number")) has an extra closing bracket; int( is added so the brackets match and the input becomes a number that can be compared with 33.
3. if a>=33: colon missing at the end of the if header.
4. ELSE: Python keywords are case-sensitive; it must be else.
© examsnet.com
Advertisements
Go to Question: