# fibonacci_sequence.py
# This program computes the nth Fibonacci number where n is a value input
# by the user using a function.
# by: Scott Gordon
def main():
print("***** Welcome to the Fibonacci Sequencer *****")
nterms = int(
input("Enter a number to represent the number of passes through the"
"Fibonacci Sequence you want: "))
def fibonacci_sequence(nterms):
counter = 0
first = 0
second = 1
temp = 0
while counter <= nterms:
print(first)
temp = first + second
first = second
second = temp
counter += 1
fibonacci_sequence(nterms)
main()
Photo by Ludde Lorentz on Unsplash
Top comments (5)
Yes, but can you do it with recursion? hehe
I don't believe I have used recursion for fibonacci as of yet in my studies. I can certainly give it a go later on though!
Yes We can do the same with recursion as well.
Code snippet:
def fibonacci_sequence(nterms):
We can do memomization here as well because here we are doing many rework as well
Interesting. have a look also here, we were discussing Fibonacci without recursion also
dev.to/joaomcteixeira/fibonacci-wi...
Awesome thanks!
Some comments have been hidden by the post's author - find out more