Fibonacci list:
This program displays first x Fibonacci numbers , Where x is a number that is requested to enter the program.
Used: if , elif , else , for
To copy or see all commands you can click on Details button below
#!/usr/bin/python
”’
author: Hopeless
task: Fibonacci write a program that will print n items of a fibonacci list
”’
print ‘\nthis program will show you fibonacci list’num = input (‘Enter a number, it will be the number of characters in the fibonacci list: ‘)
fibonacci = [1,1]
index=0
if num == 0:
print “fibonacci \n[]”
elif num == 1:
print “fibonacci \n[1]”
else:
for i in range(2,num):
index1=index+1
num1 = fibonacci[index]
num2 = fibonacci[index1]
num3 = num1+num2
fibonacci.append(num3)
index+=1
print “fibonacci”
print fibonacci
fibonacci up number:
you enter a number and the program prints fibonacci list up to a given number
Used: while
To copy or see all commands you can click on Details button below
#!/usr/bin/python
”’
author: Hopeless
task: print fibonacci list up to a given number
”’a,b=1,1
fibonacci = [1,1]max = input (‘Enter a number, it will be the max number in the fibonacci list: ‘)
while a+b <=max:
a,b =b,a+b
fibonacci.append(b)print “fibonacci list”
print fibonacci
fibonacci range:
you enter a minimum number , and maximum number .
program prints lists numbers between high number of low number
Used : while , if , not in
To copy or see all commands you can click on Details button below
#!/usr/bin/python
”’
author: Hopeless
task: print fibonacci within a given range (ex: 1,000-10,000)
”’
print “This program checks the list of Fibonacci, enter a min number and max number , range (ex: 1,000-10,000).”
nummin = input (‘Enter a number, it will be the min number of the range in fibonacci list: ‘)
nummax = input (‘Enter a number, it will be the max number of the range in fibonacci list: ‘)
fibonacci = [1,1]
index=0
num = 1while num < nummax:
index1=index+1
index2 =index+2
num1 = fibonacci[index]
num2 = fibonacci[index1]num = num1+num2
if num < nummax:
fibonacci.append(num)
index+=1
while nummin not in fibonacci:
nummin+=1print “fibonacci range list”
fibonacci.index(nummin)
print fibonacci[fibonacci.index(nummin):]