Commit c4c2a2fb by BellCodeEditor

auto save

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