26th Feb 2018, 12:02 AM
Jared Girard
Jared Girard - avatar
5 Answers
+ 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:
26th Feb 2018, 12:10 AM
Faisal
Faisal - avatar
+ 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
26th Feb 2018, 3:12 AM
LordHill
LordHill - avatar
+ 2
thank you very much
26th Feb 2018, 12:11 PM
Jared Girard
Jared Girard - avatar
+ 1
I wrote print (fib(4)) for the last line and the print outcome was 3 instead of fibonacci
26th Feb 2018, 3:03 AM
Jared Girard
Jared Girard - avatar