Is not exactly that easyprint(1+i+i)
Guide to the Fibonacci Sequence
F(n) is used to indicate the number of pairs ..., so the sequence can be expressed like this:
F(0) = 0
F(1) = 1
F(n) = F(n - 1) + F(n - 2)
In mathematical terminology, you’d call this a recurrence relation, meaning that each term of the sequence (beyond 0 and 1) is a function of the preceding terms.
# Ask the user for the number of Fibonacci numbers to generate
how_many = eval(input("How many Fibonacci numbers do you want to generate? "))
# Initialize the first two numbers
a, b = 0, 1
# Print the Fibonacci sequence
for i in range(how_many):
if i == 0:
print(a)
elif i == 1:
print(b)
else:
n = a + b
print(n)
a, b = b, n
message = '''
How many Fibonacci numbers do you want to generate?
Enter number greater than 2: '''
# Ask the user for the number of Fibonacci numbers to generate
how_many = eval(input(message))
# Initialize the first two numbers and print
a, b = 0, 1
print("\n", a, "\n", b, sep="")
# Print the Fibonacci sequence
for i in range(how_many - 2):
n = a + b
print(n)
a, b = b, n
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.