Commit 8616a667 by BellCodeEditor

auto save

parent 2db0ac81
Showing with 23 additions and 39 deletions
'''
#猴子吃桃子
def pench(n):
if n==10:
#猴子吃桃
def p(d):
#出口
if d==10:
return 1
num = (pench(n+1)+1)*2
return num
peach_num = pench(7)
print(peach_num)
n = (p(d+1)+1)*2
return n
res = p(6)
print(res)
#请用递归实现1+2+3....+num的累加和
#出口1
def sum_num(number):
if number == 1:
#实现1+2+3+...+num的累加和
#出口 1
def s_n(n):
if n==1:
return 1
sum_temp = sum_num(number-1)
return number+sum_temp
res = sum_num(3)
temp = s_n(n-1)
v = n+temp
return v
res = s_n(3)
print(res)
#求阶乘 5! 5!= 5*4*3*2*1
#兔子数量
def f(n):
if n<=2:
return 1
v = f(n-1)+f(n-2)
return v
# elif n>2:
# v = f(n-1)+f(n-2)
# return v
res = f(6)
print(res)
#汉诺塔
def hlt(n):
if n==1:
return 1
count = 2*hlt(n-1)+1
return count
res = hlt(3)
print(res)
r = f(20)
print(r)
'''
#求阶乘 5! 5!= 5*4*3*2*1
#求阶乘 5! = 5*4*3*2*1
def f(x):
if x==0:
return 0
elif x==1:
return 1
else:
y = x*f(x-1)
y = x * f(x-1)
return y
print(f(5))
r = f(5)
print(r)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment