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
Under what conditions will this code fragment print "water"?
if temp < 32 : print ("ice") elif temp < 212: print ("water") else : print ("steam")
What is the output produced by the following code?
x = 1 if x > 3 : if x > 4 : print ("A", end = ' ') else : print ("B", end = ' ') elif x < 2: if (x != 0): print ("C", end = ' ') print ("D")
What is the output of the following lines of code?
if int('zero') == 0 : print ("zero") elif str(0) == 'zero' : print (0) elif str(0) == '0' : print (str(0)) else: print ("none of the above")
Find the errors in the code given below and correct the code:
if n == 0 print ("zero") elif : n == 1 print ("one") elif n == 2: print ("two") else n == 3: print ("three")