Commit c4c2a2fb by BellCodeEditor

auto save

parent 8616a667
Showing with 21 additions and 27 deletions
'''
#猴子吃桃
def p(d):
#出口
if d==10:
def f(n):
if n==10:
return 1
n = (p(d+1)+1)*2
return n
res = p(6)
print(res)
s = (f(n+1)+1)*2
return s
a = f(8)
print(a)
#实现1+2+3+...+num的累加和
#出口 1
def s_n(n):
if n==1:
#实现1+2+3+....+num的累计和
def sum_number(number):
if number==1:
return 1
temp = s_n(n-1)
v = n+temp
temp = sum_number(number-1)
v = number+temp
return v
res = s_n(3)
print(res)
b = sum_number(3)
print(b)
#兔子数量
#斐波那契数列:兔子数量
def f(n):
if n<=2:
return 1
v = f(n-1)+f(n-2)
return v
r = f(20)
print(r)
'''
res = f(20)
print(res)
#求阶乘 5! = 5*4*3*2*1
def f(x):
#5!= 5*4*3*2*1
def fn(x):
if x==0:
return 0
elif x==1:
return 1
else:
y = x * f(x-1)
y = x*fn(x-1)
return y
r = f(5)
print(r)
c = fn(5)
print(c)
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