Script in python.org tutorial

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()

Now call the function we just defined:

… fib(2000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597

Is there any problem with this?
Does the print function require argument?

Hello Rajesh,

this example of python.org seems to be written too trivial (not actualized so far?).

You could check between : as command and as command (in Linux Terminal).

Syntax highlightening (in editor) at both possibilities are different.

Here are all explicit workarounds, which describe your intentions.

Greetz. Val.

Hello Rajesh,

this example of python.org seems to be written too trivial (not actualized so far?).

You could check between : as command and as command (in Linux Terminal).

Syntax highlightening (in editor) at both possibilities are different.

Here are all explicit workarounds, which describe your intentions.

Greetz. Val.

(sorry for second e-mail - the first was not sent properly … )

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?

From the description of print:

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?

Thank you all for your needful help. I am just a beginner. I value your great support.

Not to thank - we know - India is always thanking (usual way of Bhuddism) - no offense.

I had to do some spell-checking - my answers were not displayed 1 : 1 in forum : - here again :

Hello Rajesh,

this example of python.org seems to be written too trivial (not actualized so far?).

You could check differences between : “python” as command and “python3” as command (in Linux Terminal).

Syntax highlightening (in editor) at both possibilities are different.

Here are all explicit workarounds, which describe your intentions. The Link was not displayed either ?

Dont Know if this works now ?

" Â Â :::::::::: Â Â Â Â Â ::::::::::Â Â Â "

Greetz. Val. By the way … I am beginner too…

(sorry for third e-mail - no offense - this is only for correctly displayed answer … )