I am trying to make a Fibonacci sequence please someone help i have tried every combo i can think of just point me in the right direction no answers

Joined
Jul 25, 2024
Messages
18
Reaction score
1
here is one of my tries
fibonacci = eval(input("How many times do you want Fibonacci to repeat: "))
for i in range(fibonacci):
print(1+i+i)
 
Joined
Jul 4, 2023
Messages
510
Reaction score
63
print(1+i+i)
Is not exactly that easy


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.

Python:
# 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
Python:
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
 
Last edited:

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top