# 斐波拉切列 def fblq(size): if(size < 1): return "parm is not ture" else: a = 0 b = 1 c = 0 d = 0 while c < size: print(b) d = a+b a = b b = d c= c+1 fblq(10) # 斐波拉切列 def fblq(size): if(size < 1): return "parm is not ture" else: a,b,c =0,1,0 while c < size: print(b) a,b,c= b,a+b,c+1 fblq(10)
python语法还真是优雅。
//PHP 斐波拉切 function fblq($size=1) { $size>=1 ? true : exit("参数错误"); $a=$c=$d=0; $b=1; while ($c <= $size-1) { echo($b."<br>"); $d=$b; $b=$a+$b; $a=$d; $c=$c+1; } } fblq(8);