+ 2

How to report a error in a quiz?

In the Python course, function section, there is a quiz that asks to calculate the Fibonacci number of 4. The answer according to many widely available calculators is 3, but the quiz takes 5 as the correct answer. The function written in the quiz has the Fibonacci of zero returning 1 and it should return zero. This is the bad code in the quiz: def fib(x): if x == 0 or x == 1: return 1 else: return fib(x - 1) + fib(x - 2) print(fib(4)) It should look something like this: def fib(n): if n==1 or n==2: return 1 return fib(n-1)+fib(n-2) print(fib(4))

9th Dec 2016, 4:29 AM
Mike Smith
5 odpowiedzi
+ 5
5
25th Apr 2020, 4:36 AM
Swapnil More
Swapnil More - avatar
+ 1
What is the result of this code? def fib(x): if x == 0 or x == 1: return 1 else: return fib(x-1) + fib(x-2) print(fib(4)) out put:5
28th Apr 2020, 4:05 AM
makhan Kumbhkar
makhan Kumbhkar - avatar
0
result --------------> 5
19th Aug 2020, 4:14 PM
Ali Boukhou
Ali Boukhou - avatar
- 1
These are functionally the same. I agree that it looks different than what you would traditionally see but it works the same other than including zero as a valid input.
9th Dec 2016, 3:50 PM
James Durand
James Durand - avatar
- 2
@James Durand They are not functionally the same, they return 2 different answers, one 3 and the other 5. The point was not to compare the 2 pieces of code, but to point out the error. The correct answer is 3 and not 5.
9th Dec 2016, 6:41 PM
Mike Smith