Computer Science

What is the error in following code? Correct the code:

weather = 'raining'       
if weather = 'sunny' :
   print ("wear sunblock")
elif weather = "snow":    
   print ("going skiing") 
else :                    
   print (weather)        

Python Control Flow

73 Likes

Answer

In this code, assignment operator (=) is used in place of equality operator (==) for comparison. The corrected code is below:

weather = 'raining'       
if weather == 'sunny' :
   print ("wear sunblock")
elif weather == "snow":    
   print ("going skiing") 
else :                    
   print (weather)

Answered By

37 Likes


Related Questions