Program 34
Write a program to demonstrate try/finally and with/as.
try:
a=int(input("enter the A value:"))
b=int(input("enter the B value:"))
s=a/b
except ZeroDivisionError:
print("Can't divide by zero(b=0)")
else:
print("The divsion is=",s)
finally:
print('This is always executed')
OUTPUT:
1.=== RESTART: C:/Users/crrcse/Desktop/36.py =====
enter the A value:20
enter the B value:0
Can't divide by zero(b=0)
This is always executed
>>>
2.===== RESTART: C:/Users/crrcse/Desktop/36.py =======
enter the A value:20
enter the B value:2
The divsion is= 10.0
This is always executed
>>>
No comments:
Post a Comment