上传文件至「week12」

This commit is contained in:
2026-06-01 02:02:53 +00:00
parent 31078ddcf7
commit 185980b30f
5 changed files with 104 additions and 0 deletions

24
week12/ex1.py Normal file
View 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()