为什么num1=9就是正确结果,num1=-9结果就是1
def fact(num):
z=1
int(num)
if num<=0:
abs(num)
if num==1:
return 1
if num==0:
return 0
for i in range(1,num+1):
z=z*i
return z
num1=-9
z=fact(num1)
print(z)
def fact(num):
z=1
int(num)
if num<=0:
abs(num)
if num==1:
return 1
if num==0:
return 0
for i in range(1,num+1):
z=z*i
return z
num1=-9
z=fact(num1)
print(z)
2022-02-11
def sums (n):
refult = 0
if n > 0 and n <= 100:
while n > 0 :
refult = refult + n
n -= 1
return refult
else:
return '参数要在1-100之间'
n1 = 99
print(sums(n1))
def fact(n):
if n == 1:
return 1
elif n < 1:
return '参数要在1-100之间'
elif n <= 100:
return n + fact(n-1)
else:
return '参数要在1-100之间'
n2 = 99
print(fact(n2))
以上是我自己看完示例写的,不一定是最好的,但是我现在也是初学,只能写成这样了,希望对你有参考作用
举报