Home > Problem, Projects/Experiments, Python > Python Project

Python Project




Python: Fibonacci Numbers


Even Fibonacci Numbers

Fibonacci Sequence is generated by adding the previous two terms, so the N number in the sequence will be Xn=(Xn-1) + (Xn-2). Example: by starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

The Task: Get the Fibonacci sequence range from the user and count how many even valued terms is there. The user range should not be more than 10000 number.



The Code:


def get_Fibonacci_Sequence(rfrom,rto):
n1=rfrom
n2=rfrom+1
count=0
for x in range (rfrom,rto):

fab=n1+n2

n1=n2

n2=fab

# Check if the fab is even, the increment the counter

if fab%2==0 :

count =count +1
# After finish print the output
print”Between”,rfrom,” and “,rto,” there is “,count,”even Fibonacci number.”

range_ok =”no”
while range_ok==”no”:

print(‘Your range must be less than 10,000:’)

# Get the numbers from the user.

rfrom=int(input(‘Enter the range From:’))

rto=int(input(‘Enter the range To:’))

# Check if the numbers are less than 10000

if (rto – rfrom) < 10000 : range_ok ="yes"

#Call the function
get_Fibonacci_Sequence(int(rfrom),int(rto))






Follow me on Twitter..

Advertisements
  1. April 11, 2019 at 5:25 am

    This is my Favorite language😍

    http://www.techwideweb.com

  1. No trackbacks yet.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s