Computer Science

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

Python Control Flow

62 Likes

Answer

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

Answered By

39 Likes


Related Questions