Quick actions

cmd+k|ctrl+k

Navigation

Languages

Day 13 -  Part D

Snippet info

Language

Python

Visibility

public

Author

tendycode

Created

2025-05-16T09:23:42.542227Z

Updated

2025-05-16T09:37:38.686536Z

# try & except
def a():
    pass
x='1'
y= 0
try:
    print(x/y)
except:
    print("data error")
finally:
    print("this line of code will run, no matter what")
#finally should follow with try & except
    
# except ZeroDivisionError:
#     print("Y is zero, can't compute") #(when y = 0)
# except TypeError:
#     print("Please input numeric value")#(when x='1')
# except NameError:
#     print("please input numeric value instead of unknown symbol")#(when a is function)
INFO