+ 6
I need help with this fibonacci
5 Réponses
+ 2
The actual function should be fine, but the problem is how your calling it. In your code, you set the function fib to have one parameter, n. When you call the function in the print function however, you aren't adding any parameters, meaning that you're just telling the program to print the location of the function.
Try changing the last line, so that it looks similar to this:
print(fib(4)) #You can change the number to whatever, you can even set it to user input if you want
Hope this helped! d:
+ 2
that's because 3 is the 4th value in the Fibonacci series. print each iteration.
def fib (n):
a,b = 1,1
for i in range (n-1):
a,b=b,a+b
print(a, end=' ')
fib(10)
Whatever number you put in the fib(n) at the bottom is how many steps it will print.. all I changed of your code was replacing return with print and changing the print to a function call
+ 2
thank you very much
+ 1
I wrote print (fib(4)) for the last line and the print outcome was 3 instead of fibonacci