Computer Science
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")
Python
Python Control Flow
67 Likes
Answer
C D
Working
As value of x is 1 so statements in the else part of outer if i.e. elif x < 2:
will get executed. The condition if (x != 0)
is true so C is printed. After that the statement print ("D")
prints D.
Answered By
24 Likes
Related Questions
Rewrite the following code fragment that saves on the number of comparisons:
if (a == 0) : print ("Zero") if (a == 1) : print ("One") if (a == 2) : print ("Two") if (a == 3) : print ("Three")
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 error in following code? Correct the code:
weather = 'raining' if weather = 'sunny' : print ("wear sunblock") elif weather = "snow": print ("going skiing") else : print (weather)
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")