day16 --------------------------------------------------------------- 实例024:斐波那契数列II 题目 有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13-求出这个数列的前20项之和. 分析:就是斐波那契数列的后一项除以前一项,于是写了两个函数 1 def fbs(num): 2 a = [0,1] 3 if num<=2: 4 return a 5 else: 6 for i in range(1,int(…
def fabm(n): if n < 1: print('输入不能小于1') return -1 if n == 1 or n == 2: return 1 else: return fabm(n-1) + fabm(n-2) result = fabm(19) if result != -1: print('结果是%d' % result)…
# 递归 def myAdd(a, b): c = a + b print(c) if c > 100: return return myAdd(a + 1, c) #最大递归深度是1000 myAdd(2, 3) # 功能同上递归 a = 2 b = 3 for i in range(1000): c = a + b print(c) a += 1 b = c def myFibo(a, b): c = a + b print(c) if c > 500: return return myF…
随机输入求素数: x = int(input("please enter the number:")) if x != 1: for i in range(2, x): if x % i == 0: break else: print(x) 求10W以内全部的素数 c = 0 for x in range(2,100000): for i in range(2, int(x ** 0.5)+1): if x % i == 0: break else: c += 1 print(x) p…