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

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post