Msathmi
发表于 2019-9-15 11:21:35
n=int(input("求斐波那契数列第_个数:"))
list=
def fs(n):
i=1
for i in range(1,n):
list.append(list+list)
i+=1
return list
if n==1:
print(0)
elif n==1:
print(1)
else:
print(fs(n))
九五二七
发表于 2019-10-29 20:49:34
list1=
for i in range(10):
a=list1+list1
list1.append(a)
print(list1)
ka233siji
发表于 2020-1-16 11:09:22
time = int(input('查询前n项,n为:'))
f1,f2 = 1,1
if time ==1 :
print(f1)
elif time == 2:
print(f1,f2,end=' ')
else :
print(f1,f2,end=' ')
for i in range(time-2) :
temp = f2
f2 += f1
f1 = temp
print(f2,end=' ')
Python学好
发表于 2020-1-29 20:29:33
def fibs(n):
a, b = 0, 1
while n != 1:
a, b = b, a + b
n -= 1
return a
ouyunfu
发表于 2020-2-11 14:57:55
def fib(n):
a,b=1,1
for i in range (n-1):
a,b=b,a+b
return a
print(fib(4))
xuanyuan0116
发表于 2020-2-22 11:27:24
print('----------每日练习题6----------')
#题目:斐波那契数列
def feb(n):
if n > 2:
return feb(n-1) + feb(n-2)
else:
return 1
list1 = []
def feb1(n):
n1 = 0
n2 = 1
n3 = 1
if n < 1:
print('输入错误!')
reutun -1
while (n-2) > 0:
n3 = n2 + n1
n1 = n2
n2 = n3
n -= 1
global list1
list1.append(n3)
return n3
youngorc
发表于 2020-2-25 15:07:23
list1=
num=int(input("需要输出前几个斐波那契数列的值:"))
if num >=2:
for i in range(2,num):
list1.append(list1[-1]+list1[-2])
print("前%i个斐波那契数列的值为:"%(num)+str(list1))
君子好逑
发表于 2020-2-25 16:58:52
temp=input("您所需要的斐波那契数列的长度为:")
long1=int(temp)
if (long1==1):
print(0)
elif (long1==2):
print(0,end=" ")
print(1)
else :
print(0,end=" ")
print(1,end=" ")
i=long1-2
num1=0
num2=1
while i:
num3=num1+num2
print(num3,end=" ")
num1=num2
num2=num3
i-=1
十月故里
发表于 2020-4-1 20:44:19
本帖最后由 十月故里 于 2020-4-1 20:46 编辑
def fun():
a=0
b=1
while True:
print(a)
a,b=b,a+b
yield
君子好逑
发表于 2020-4-4 15:07:29
temp=input("您所需要的斐波那契数列的长度为:")
long1=int(temp)
if (long1==1):
print(0)
elif (long1==2):
print(0,end=" ")
print(1)
else :
print(0,end=" ")
print(1,end=" ")
i=long1-2
num1=0
num2=1
while i:
num3=num1+num2
print(num3,end=" ")
num1=num2
num2=num3
i-=1
宋太皇
发表于 2020-4-4 16:09:05
a=0
b=1
while a<1000:
print(a)
print(b)
a=a+b
b=a+b
rofok
发表于 2020-4-12 00:10:10
# 题目:斐波那契数列。
# 程序分析:斐波那契数列(Fibonacci sequence),又称黄金分割数列,指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、……。
def Fibonacci(n):
if n == 1:
return 0
if n == 2:
return 1
return Fibonacci(n-1)+Fibonacci(n-2)
print("the way1")
num = int(input("输入斐波拉契数列长度"))
for i in range(1, num+1):
print(Fibonacci(i), end=' ')
print("\n", "the way2")
def Fibonacci2():
s =
if num == 1:
print(s, end=" ")
if num == 2:
print(s, s, end=" ")
elif num >= 3:
print(s, s, end=" ")
for i in range(1, num - 1):
s.append(s[-1] + s[-2])
print(s[-1], end=' ')
Fibonacci2()
尔东方
发表于 2020-4-27 11:37:45
def fib(n):
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
fib(1000)
san1412
发表于 2020-5-7 08:53:04
def Fibonacci(n):
if n == 1 or n == 2:
return 1
else:
return Fibonacci(n-1) + Fibonacci(n-2)
num = int(input("请输入一个正整数:"))
result = Fibonacci(num)
print('第 %d 项斐波那契数列为: %d '% (num,result))
ForPorsche
发表于 2020-5-22 22:53:58
a, n = 0, 0
b = 1
num = int(input('想要输出前多少项:'))
while n < num:
print(a, end=' ')
a, b = b, a + b
n += 1
鲨鱼辣椒1
发表于 2020-7-24 16:38:27
def fib(n):
if n <= 1:
return 1 # return 结束函数,并返回一个值
else:
return fib(n - 1) + fib(n - 2)
number = int(input("请输入一个整数:"))
result = fib(number) # 实参是number,形参是n
print(result)
想起飞吗
发表于 2020-9-14 20:46:06
def fs(i):
if i==1:
return 0
if i==2:
return 1
else:
return fs(i-1)+fs(i-2)
谢啾啾
发表于 2020-10-27 16:35:35
def fab(n):
if n == 1 or n == 2:
return 1
else:
return fab(n-1)+fab(n-2)
x = int(input('输入斐波那契数列的阶数:'))
for i in range(1, x+1):
print(fab(i), end=' ')
逃兵
发表于 2020-12-18 11:33:46
n=int(input())
lst=
lst = 1
for i in range(3,n):
lst=lst+lst
for i in lst:
print(i)
一块钱赫赫
发表于 2021-2-19 09:50:41
num =
i = 2
while i < 10 :
num.append(num + num)
i += 1
print(num)