CBSE Class 11 Computer Science Question 92 of 161

Flow of Control — Question 1

Back to all questions
1
Question

Question 1

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

Answer

if (a == 0) : 
  print ("Zero")
elif (a == 1) :
  print ("One")
elif (a == 2) :
  print ("Two")
elif (a == 3) :
  print ("Three")
Answer