上传文件至「week12」
This commit is contained in:
24
week12/ex1.py
Normal file
24
week12/ex1.py
Normal file
@@ -0,0 +1,24 @@
|
||||
def handleZeroDivisionError(lmbd):
|
||||
def runlambda(*args,**kwargs):
|
||||
try:
|
||||
return lmbd(*args,**kwargs)
|
||||
except ZeroDivisionError:
|
||||
print("Zero division detected!")
|
||||
return runlambda
|
||||
|
||||
# usage: handleZeroDivisionError(lambda)()
|
||||
# or:
|
||||
|
||||
@handleZeroDivisionError
|
||||
def div(a,b):
|
||||
return a/b
|
||||
|
||||
def main():
|
||||
print(handleZeroDivisionError(lambda:1/0)())
|
||||
print(handleZeroDivisionError(lambda:1/1)())
|
||||
print(div(1,0))
|
||||
print(div(1,1))
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user