How do I print a fibonacci sequence to the nth number in Python?

前端 未结 7 1587
忘了有多久
忘了有多久 2020-12-31 22:24

I have a homework assignment that I\'m stumped on. I\'m trying to write a program that outputs the fibonacci sequence up the nth number. Here\'s what I have so far:

相关标签:
7条回答
  • 2020-12-31 22:51
    def fib(n):
       if n == 1:
          return(1)
       elif n == 0:   
          return(0)            
       else:                      
          return fib(n-1) + fib(n-2)
    
    my_num = int(input("Enter a number:"))
    print fib(my_num)
    

    Im not really sure what your question is... but the answer is probably something like this

    0 讨论(0)
提交回复
热议问题