morxrc
发表于 2017-8-23 14:44:07
print('__________斐波那契数列______________')
x1=0
x2=1
list=
i=0
while len(list)<=50:
temp=list+list
list.append(temp)
i+=1
print(list)
gausser
发表于 2017-9-5 22:06:02
def CalculationFibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return CalculationFibonacci(n - 1) + CalculationFibonacci(n - 2)
n = int(raw_input("Enter the Fibonacci Number: "))
for i in range(n):
print CalculationFibonacci(i),
递归。。。。
BngThea
发表于 2017-9-11 11:12:59
list0 =
for i in range(100):
list0.append(list0 + list0)
print(list0)
张大象
发表于 2017-9-13 17:13:08
def fib(n):
yield 0
x = 1
y = 1
yield x
for i in range(2,n):
x,y = y,x+y
yield x
for i in fib(10):
print(i)
易水寒楠
发表于 2017-9-23 00:11:29
递归法,算到小于90的序列
# -*-coding:gbk-*-
__author__ = 'chennan'
n1=0
print(n1)
n2=1
print(n2)
n3=n1+n2
print(n3)
while n3<90:
print(n3)
n1=n2
n2=n3
n3=n1+n2
驻火蚁
发表于 2017-9-24 21:35:36
def fab(max):
n, a, b = 0, 0, 1
while n < max:
print(b)
a, b = b, a + b
n = n + 1
驻火蚁
发表于 2017-9-25 10:45:08
余欲渔 发表于 2017-4-11 14:32
c=
for i in range(30):
c.append(c[-1]+c[-2])
print(c[-3],end='/')
为什么c.append(c[-1]+c[-2])就是递归了 c.append(c+c)就不可了 ???
石小龙
发表于 2017-11-8 21:57:44
r = int(input('您要求第几个数:'))
x = 1
y = 1
for i in range(1,r):
x,y = y,x + y
print(x)
流浪者python
发表于 2017-11-20 17:32:17
def fib(n):
if n <= 1:
return 0
if n == 2:
return 1
else:
return fib(n-1) + fib(n-2)
n = int(input('请输入大于0的整数:'))
fib_num = []
for i in range(1, n + 1):
fib_num.append(fib(i))
print(fib_num)
achencan
发表于 2017-11-21 17:51:55
新人。。。决定从前面的题慢慢开始做,不要怪我挖坟!
a=1
b=0
c=0
for i in range(30):
c=a+b
b=a
a=c
print c
一枚独品
发表于 2018-1-3 14:38:11
新手·ing 发表于 2017-3-26 14:00
def fib(n):
a,b = 1,1
for i in range(n-1):
a=b
b=a+b
print(a)
fib(10)
def fib(n):
a,b = 1,1
for i in range(n-1):
a,b=b,a+b
print(a)
fib(10)
请问这两段程序,结果不一样,a,b=b,a+b和a=bb=a+b,赋值方式是不一样的吗?
wojiaodabai
发表于 2018-1-17 15:53:02
a=0
b=1
for i in range(0,10):
print(b)
a,b=b,a+b
有鼻泡的犀牛
发表于 2018-1-17 16:50:59
def z():
a = 0
b = 1
while(a <1000):
print(a)
a,b = b , a + b
z()
1141429506
发表于 2018-1-26 19:28:28
list1=
for i in range(30):
m=list1+list1
list1.append(m)
print(list1)
z1446773686
发表于 2018-2-8 15:19:52
def F1_2(n):
dire = []
f1 = 0
f2 = 1
dire.append(f1)
dire.append(f2)
for i in range(0 , n-1):
f1 = f1 + f2
f2 = f2 + f1
dire.append(f1)
dire.append(f2)
print(dire)
运行结果如下:
>>> F1_2(5)
nforev
发表于 2018-2-9 16:15:40
def fib(x,y):
print(y)
if y < 10000:
return fib(y,x+y)
fib(0,1)
大头目
发表于 2018-2-13 15:08:49
def fab(m):
if m < 1:
print('number error!')
return -1
if m == 1 or m == 2:
return 1
else:
return fab(m - 1) + fab(m - 2)
results = fab(20)
凌九霄
发表于 2018-2-13 16:18:00
def Fibonacci(n):
fibo =
if n == 1:
print(fibo)
elif n == 2:
print(fibo)
else:
for i in range(3, n + 1):
fibo.append(fibo[-2] + fibo[-1])
return fibo
print(Fibonacci(10))
ultraji
发表于 2018-2-19 12:18:16
fi = [-1 for i in range(0,1000)]
def fibo(x):
if fi != -1:
return fi
else:
return fibo(x-1) + fibo(x-2)
fi,fi= 0,1
t = int(input())
print (fibo(t))
lchelement
发表于 2018-2-25 11:09:28
'''0、1、1、2、3、5、8、13、21、34、……。
0 n=0
fn={1 n=1
f(n-1)+f(n-2) n>=2'''
def feb(n):
if n==0:
return 0
elif n==1:
return 1
else:
return feb(n-1)+feb(n-2)
i=0
while i<20:
print(feb(i),end=' ')
i +=1