def factorial(n):
result = n
for i in range(1, n):
result *= i
return result
number = int(input("请输入一个正整数:"))
result = factorial(number)
print("%d的阶乘是:%d" %(number, result))
-----
def factorial(n):
if n == 1:
return 1
else:
return n* factorial(n - 1)
number = int(input("请输入一个正整数:"))
result = factorial(number)
print("%d的阶乘是:%d" %(number, result))
def f(n):
if n == 1:
ret = 0
elif n == 2:
ret = 1
else:
ret = f(n-1)+f(n-2)
return ret
print(f(4))
def f(n):
if n == 1:
return 0
elif n == 2:
return 1
return f(n-1)+f(n-2)
print(f(5))
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。