Conditionals Output#

  • Find the output of the following code.

  • Please don’t run the code before giving your answer.     

Question-1#

print(True+False+3+True)

Solution

5

Question-2#

x = 20
y = 100

b1 = x == y
b2 = x < y

print(b1)
print(b2)
print(b1 and b2)
print(b1 or b2)

Solution

False
True
False
True

Question-3#

x = 10

if x<7:
  print('A')

Solution

No output!

Question-4#

x = 20

if x > 10:
  print('A')
elif x > 15:
  print('B')
else:
  print('C')

Solution

A

Question-5#

x = 20

if x > 10:
  print('A')
if x > 15:
  print('B')

Solution

A
B

Question-6#

x = 17
y = 9

if x<15 and y>5:
  print('A')
elif x>7 and y>5:
  print('B')
elif x>10 and y>6:
  print('C')
else:
  print('D')

Solution

B

Question-7#

x = 25

if x < 30:
  print('A')
  if x < 20:
    print('B')

Solution

A

Question-8#

x = 25

if x < 30:
  print('A')
  if x < 40:
    print('B')

Solution

A
B

Question-9#

x = 25

if x < 10:
  print('A')
  if x < 40:
    print('B')

Solution

No output!

Question-10#

if 10:
  print('USA')

Solution

USA

Question-11#

if 0:
  print('USA')

Solution

No output!

Question-12#

if 0==0 :
  print('USA')

Solution

USA

Question-13#

x = 10

if x > 2*x:
  print(x)
print(2*x)

Solution

20

Question-14#

x = 10

if x > 2*x:
  print(x)
  print(2*x)

Solution

No output!

Question-15#

if True:
  if 1:
    if 5:
      if 0:
        print('A')
      else:
        print('B')
    else:
      print('C')

Solution

B

Question-16#

x = 5

if x > 3:
  print('A')
if x > 4:
  print('B')
  print('?')
if x > 10:
  print('C')
  print('#')
print('D')

Solution

A
B
?
D

Question-17#

x = '3'

try:
  print(x+5)
except:
  print('ERROR')

Solution

ERROR

Question-18#

x = True

try:
  print(x+5)
except:
  print('ERROR')

Solution

6