随机产生10-30之间的整数,存储到列表中,求它们的阶乘之和
大佬们,求帮助
程序代码:
def foo(m): if m==1 | m==0 :return 1 result=1 while m>0: result*=m m-=1 return result import random lst=[] for i in range(5): lst.append(random.randint(10,30)) sum=0 for x in lst: sum+=foo(int(x)) print("%d !=%d"%(x,foo(int(x)))) print(sum) ========================== RESTART: C:\Python3\1.py ========================== 13 !=6227020800 16 !=20922789888000 25 !=15511210043330985984000000 24 !=620448401733239439360000 16 !=20922789888000 16131658445106077230156800 >>>
[此贴子已经被作者于2019-5-16 10:44编辑过]