代码如下:
tofile = open('阶乘.txt','w',encoding='utf-8') fact = 1 for i in range(1,101): fact *= i print(f'{i}! = {fact}', file=tofile) tofile.close()