第三方Python包:
Loguru: 更好的打印程序异常
snoop: 打印函数中正在执行的代码行
pip install loguru
from loguru import logger
from itertools import combinations
def division(num1: int, num2: int):
return num1/num2
@logger.catch # !!!!!!!!!!!!!!Add this to track errors!!!!!!!!!!
def divide_numbers(num_list: list):
for comb in combinations(num_list, 2):
num1, num2 = comb
res = division(num1, num2)
print(f"{num1} divided by {num2} is equal to {res}.")
if __name__ =='__main__':
num_list = [2, 1, 0]
divide_numbers(num_list)
pip install snoop
import snoop
@snoop(depth=2) # !!!!!!!!!!!!!!Add this to track errors!!!!!!!!!!
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))
if __name__ == "__main__":
num = 5
print(f"The factorial of {num} is {factorial(num)}")