def fib(n): # write Fibonacci series up to n
… “”“Print a Fibonacci series up to n.”“”
… a, b = 0, 1
… while a < n:
… print(a, end=’ ')
… a, b = b, a+b
… print()
…
Not that I can see. The Fibonacci series starts with 0 and 1 and the next in the sequence is the sum of the previous two:
0+1=1
1+1=2
1+2=3 etc.
So no problem. It stops when the next item in the sequence would be larger than 2000: 987 + 1597 > 2000. It works exactly as advertised. What do you think is a problem?
If no objects are given, print() will just write end .
Now in the loop end is defined as the empty string. So it writes all the output on one line. After the last one the cursor will be after “1597”, making a mess of anything printed afterwards that expects a line ending before it. So the programmer thoughtfully added a print, printing a newline (the default for end).
I advise you to experiment and try things out for yourself. Reading as much code as you can is important, but trying out things will also help you going faster in learning to code. What happens if I add something to the print function? Or if I leave it out all together?