KnowledgeBoat Logo
|

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"

Python Control Flow

6 Likes

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")  

Answered By

2 Likes


Related Questions