0
can someone help me to fix the error to return 10 Fibonacci series numbers?
2 Answers
+ 1
It was almost good.
Keep in mind that whatever is inside the while loop will repeat in each cycle. So you don't want to reset your loop variables and your list every time, put them before the while.
Also pay attention to indentation, the print in the end must be indented the same level as while.
def fibonacci():
prev=0
new=1
lst=[0,1]
while True:
u=lst[prev]+lst[new]
lst.append(u)
prev+=1
new+=1
if len(lst)==10:
break
else:
continue
print(lst)
fibonacci()
+ 1
Thank you so much Tibor Santa your answer helped me a lot :)