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


Answer:-

It will give an error.

Explanation:-

"zero" is a string and the int() function can not convert the alphabet into an integer.

So, the correct code is:-

if int('0') == 0 :
    print ("zero")
elif str(0) == 'zero' :
    print (0)
elif str(0) == '0' :
    print (str(0))
else :
    print ("none of the above")

Output:-


zero
>>>


2 Comments

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

Post a Comment

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

Previous Post Next Post