QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A CBSE12A-2015-B02B #6352

Question:

What will be the output of the following python code ? Explain the try and except used in the code.

A=0
B=6
print 'One'
try:
    print 'Two'
    X=B/A
    Print 'Three'
except ZeroDivisionError:
    print B*2
    print 'Four'
except:
    print B*3
    print 'Five'

Answer:

One
Two
12
Four
The code written within try triggers the exception written after
except ZeroDivisionError: in case there is a division by zero error
otherwise the default exception is executed