-2

I'm just started learning python.. How to return list? Is here any error in code.?

def fibonocci(x,i):
    if len(lst)>=x:
        return lst
    v=lst[i-1]+lst[i-2]
    lst.append(v)
    fibonocci(x,i+1)

n=int(input("Enter a number: "))
lst=[0,1]
print(fibonocci(n,2))
mani kumar
  • 51
  • 2
  • 6

1 Answers1

1

You don't return anything in case len(lst) < x.

You should change fibonocci(x, i+1) to return fibonocci(x, i+1).

DeepSpace
  • 78,697
  • 11
  • 109
  • 154