Home > other >  Given my python Fibonacci sequence
Given my python Fibonacci sequence

Time:11-16

Program analysis: the Fibonacci sequence (the Fibonacci sequence)
 a, b=0, 1 
While b & lt; 10:
Print (b)
A, b=b, a + b


Perform the above procedure, the output is:



Comments: the first time: output the initial value of 1 b, then execute the code. A, b=b, a + b works is now a=0 b=1 a + b=1 assigned to b, is now a value of 1, b has a value of 1,
The second time: the output current value 1 b, perform a + b=1 + 1=2, b 2 assignment results as the calculating results, a b in the calculation of the assignment of a value of 1.
Third time: output current value 2 b, perform a=b=1 + 2=3, b assignment results for calculating 3, a b in the calculation of the assignment has a value of 2.
Fourth: output current value 3 b, perform a=b=2 + 3=5, b assignment results for calculating 5, assignment of b has a value of 3.
Over 5: output current value 5 b, perform a=b=3 + 5=8, b assignment results for calculating results 8, assignment of b has a value of 5.

Myself before learning python Fibonacci Numbers mentally the code analysis, and then studied, the above is my personal humble opinion, the hope can help beginners python's classmate,
  • Related