Python Project: Fibonacci Numbers
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))
This is my Favorite language😍
http://www.techwideweb.com
Yes indeed, fast easy and rich.