Informatics Practices
Find error in the following code (if any) and correct it by rewriting the code and underline the corrections:
code=input ("Enter season code : ")
if code=w:
print "winter season"
elif code==r:
PRINT "rainy season"
else:
Print "summer season"
Answer
code = input("Enter season code : ")
if code=w: #Error 1
print "winter season" #Error 2
elif code==r: #Error 3
PRINT "rainy season" #Error 4
else:
Print "summer season" # Error 5
Error 1 — The assignment operator '=' is used instead of equality operator '==' in the if statement and the string 'w' should be enclosed in quotes.
Error 2 — Parentheses around the print statement are missing.
Error 3 — String 'r' should be enclosed in quotes.
Error 4 — The print statement should be in lowercase letters and there should be parentheses around the print statement.
Error 5 — The print statement should be in lowercase letters and there should be parentheses around the print statement.
The corrected code is :
code = input("Enter season code: ")
if code == "w":
print("winter season")
elif code == "r":
print("rainy season")
else:
print("summer season")
Related Questions
What are compound statements?
Construct a logical expression to represent each of the following conditions:
(a) Marks are greater than or equal to 70 but less than 100.
(b) Num is between 0 and 5 but not equal to 2.
(c) Answer is either 'N' OR 'n'.
(d) Age is greater than or equal to 18 and gender is male.
(e) City is either 'Kolkata' or 'Mumbai'.
Give the output of the following when num1 = 4, num2 = 3, num3 = 2.
num1 += num2 + num3 print(num1)Give the output of the following when num1 = 4, num2 = 3, num3 = 2.
num1 = num1 ** (num2 + num3) print (num1)