@@ -29,16 +29,16 @@ called :file:`fibo.py` in the current directory with the following contents::
29
29
30
30
def fib(n): # write Fibonacci series up to n
31
31
a, b = 0, 1
32
- while b < n:
33
- print(b , end=' ')
32
+ while a < n:
33
+ print(a , end=' ')
34
34
a, b = b, a+b
35
35
print()
36
36
37
37
def fib2(n): # return Fibonacci series up to n
38
38
result = []
39
39
a, b = 0, 1
40
- while b < n:
41
- result.append(b )
40
+ while a < n:
41
+ result.append(a )
42
42
a, b = b, a+b
43
43
return result
44
44
@@ -52,17 +52,17 @@ the current symbol table; it only enters the module name ``fibo`` there. Using
52
52
the module name you can access the functions::
53
53
54
54
>>> fibo.fib(1000)
55
- 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
55
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
56
56
>>> fibo.fib2(100)
57
- [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
57
+ [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
58
58
>>> fibo.__name__
59
59
'fibo'
60
60
61
61
If you intend to use a function often you can assign it to a local name::
62
62
63
63
>>> fib = fibo.fib
64
64
>>> fib(500)
65
- 1 1 2 3 5 8 13 21 34 55 89 144 233 377
65
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
66
66
67
67
68
68
.. _tut-moremodules :
@@ -92,7 +92,7 @@ module directly into the importing module's symbol table. For example::
92
92
93
93
>>> from fibo import fib, fib2
94
94
>>> fib(500)
95
- 1 1 2 3 5 8 13 21 34 55 89 144 233 377
95
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
96
96
97
97
This does not introduce the module name from which the imports are taken in the
98
98
local symbol table (so in the example, ``fibo `` is not defined).
@@ -101,7 +101,7 @@ There is even a variant to import all names that a module defines::
101
101
102
102
>>> from fibo import *
103
103
>>> fib(500)
104
- 1 1 2 3 5 8 13 21 34 55 89 144 233 377
104
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
105
105
106
106
This imports all names except those beginning with an underscore (``_ ``).
107
107
In most cases Python programmers do not use this facility since it introduces
@@ -145,7 +145,7 @@ executed as the "main" file:
145
145
.. code-block :: shell-session
146
146
147
147
$ python fibo.py 50
148
- 1 1 2 3 5 8 13 21 34
148
+ 0 1 1 2 3 5 8 13 21 34
149
149
150
150
If the module is imported, the code is not run::
151
151
0 commit comments