def mystery(n):
a, b = 0, 1
while a < n:
print (a)
a, b = b, a + b
If someone could give me a line by line explanation of this code, as also inform of why it will not run, and what extra code needs to be added.
def mystery(n): # define a function named "mystery", that takes one argument called "n"
a, b = 0, 1 # make a variable named "a" and set it to 0; make a variable named "b" and set it to 1
while a < n: # as long as "a" is smaller than "n"
print (a) # display the value contained in "a" on the screen
a, b = b, a + b # set "b" to the sum of "a" and "b"; set "a" to the old value of "b" (before it was set to the sum of "a" and "b")
来源:https://stackoverflow.com/questions/28949809/step-by-step-explanation-of-this-code