Skip to content
Advertisement

What am doing wrong in this piece of fibonacci code in python docs vs my re implementation?

Python docs:

JavaScript

My reimplementation:

JavaScript

Advertisement

Answer

The difference between

JavaScript

and

JavaScript

is that in the second one, a is assigned value of b, and then b is assigned the sum of a and b, which means it is twice its original value.

Consider:

JavaScript

This gives

JavaScript

Contrarily:

JavaScript

which gives:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement