免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
斐波納契--python
源代碼:
#!usr/bin/python3
import sys
def fibonacci(n): #generator function
   a, b, counter = 0, 1, 0
   while True:
      if (counter > n): 
         return
      yield a
      a, b = b, a + b
      counter += 1
f = fibonacci(5) #f is iterator object

while True:
   try:
      print (next(f), end=" ")
   except StopIteration:
      sys.exit()        #結(jié)果0 1 1 2 3 5 

結(jié)果:

-----------------------------------------------------------------
#!/usr/bin/python3
 
# Fibonacci series: 斐波納契數(shù)列
# 兩個(gè)元素的總和確定了下一個(gè)數(shù)
a, b = 0, 1
while b < 10:
    print(b)
    a, b = b, a+b
    
1
1
2
3
5
8
-----------------------------------------------------------------
#!/usr/bin/python3
 
# Fibonacci series: 斐波納契數(shù)列
# 兩個(gè)元素的總和確定了下一個(gè)數(shù)
a, b = 0, 1
while b < 1000:
    print(b, end=',')
    a, b = b, a+b
    #1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
--------------------------------------------------------------
斐波拉契數(shù)列
def fib(max): n, a, b = 0, 0, 1 while n < max: print(b) a, b = b, a + b n = n + 1 return 'done'fib(6)112358'done'
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Python并發(fā)編程:利用多線程和多進(jìn)程提高性能
ubuntu下python3及idle3的安裝
Python|運(yùn)用列表求斐波那契數(shù)列
Fibonacci 斐波那契數(shù)列的幾種寫法、時(shí)間復(fù)雜度對比
【Python技巧】內(nèi)存管理大揭秘:如何提升程序執(zhí)行效率?
青少年P(guān)ython編程系列28:Python中函數(shù)的遞歸調(diào)用
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服