1 eg: 2 def sum(max_data): 3 result = [] 4 while True: 5 if len(result) == 0: 6 result.append(1) 7 elif len(result) == 1: 8 result.append(1) 9 else: 10 v = result[-1] + result[-2] 11 if v > max_data: 12 break 13 result.append(v) 14 return result 15 c = sum(100) 16 print(c) 17 # -------------[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]------------
原文:https://www.cnblogs.com/weiliwei-lucky/p/weiliwei-lucky.html