adplus-dvertising
frame-decoration

Question

What is the output of the following piece of code?
def a(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return a(n-1)+a(n-2)
for i in range(0,4):
    print(a(i),end=" ")

a.

0 1 2 3

b.

An exception is thrown

c.

0 1 1 2 3

d.

0 1 1 2

Posted under Python

Answer: (d).0 1 1 2

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the following piece of code?