Python学习第六天——Fibonacci
程序员文章站
2022-04-24 20:36:55
1 #coding=utf-8 2 #Version:python 3.6.0 3 #Tools:Pycharm 2017.3.2 4 _date_ = '2018/4/19/019 16:26' 5 6 def fib(max): 7 n,a,b = 0,0,1 8 while n <= max: ......
1 #coding=utf-8 2 #Version:python 3.6.0 3 #Tools:Pycharm 2017.3.2 4 _date_ = '2018/4/19/019 16:26' 5 6 def fib(max): 7 n,a,b = 0,0,1 8 while n <= max: 9 print(n," --> ",b) 10 a,b,n= b,a+b,n+1 11 # b = a + b 12 # a = b 13 #n += 1 14 return "done" 15 16 print(fib(50))
E:\ProgramData\Anaconda3\python.exe D:/Python_proc/s14/week4/day1/Fibonacci.py 0 --> 1 1 --> 1 2 --> 2 3 --> 3 4 --> 5 5 --> 8 6 --> 13 7 --> 21 8 --> 34 9 --> 55 10 --> 89 11 --> 144 12 --> 233 13 --> 377 14 --> 610 15 --> 987 16 --> 1597 17 --> 2584 18 --> 4181 19 --> 6765 20 --> 10946 21 --> 17711 22 --> 28657 23 --> 46368 24 --> 75025 25 --> 121393 26 --> 196418 27 --> 317811 28 --> 514229 29 --> 832040 30 --> 1346269 31 --> 2178309 32 --> 3524578 33 --> 5702887 34 --> 9227465 35 --> 14930352 36 --> 24157817 37 --> 39088169 38 --> 63245986 39 --> 102334155 40 --> 165580141 41 --> 267914296 42 --> 433494437 43 --> 701408733 44 --> 1134903170 45 --> 1836311903 46 --> 2971215073 47 --> 4807526976 48 --> 7778742049 49 --> 12586269025 50 --> 20365011074 done Process finished with exit code 0