Building fibonacci list(and more) – Python

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

fibonacci.png
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

 

Untitled.png



fibonacci up number:

you enter a number and the program prints fibonacci list up to a given number

Used: while

fibonaccimax.png
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

 

Untitled2.png



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

fibonacci range.png

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 = 1

while 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+=1

print “fibonacci range list”
fibonacci.index(nummin)
print fibonacci[fibonacci.index(nummin):]

 

Untitled3.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s