Skip to content

Commit e03ccaa

Browse files
committed
modify the code of chapter03
1 parent 83f2277 commit e03ccaa

5 files changed

Lines changed: 42 additions & 1 deletion

File tree

python3code/chapter03/decorate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# coding:utf-8
2+
'''
3+
filename: decorate.py
4+
'''
25

36
def p_decorate(func):
47
def wrapper(name):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding:utf-8
2+
"""
3+
the better Fibonacci
4+
filename: fibsbetter.py
5+
"""
6+
7+
m = {0:0, 1:1}
8+
9+
def fib(n):
10+
if not n in m:
11+
m [n] = fib(n-1) + fib(n-2)
12+
return m[n]
13+
14+
f = fib(10)
15+
print(f)

python3code/chapter03/foo1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#coding:utf-8
2+
'''
3+
filename: foo1.py
4+
'''
5+
def foo():
6+
def bar():
7+
print("bar() is running")
8+
print("foo() is running")
9+
10+
foo() #调用函数

python3code/chapter03/foo2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#coding:utf-8
2+
'''
3+
filename: foo2.py
4+
'''
5+
def foo():
6+
def bar():
7+
print("bar() is running")
8+
bar() #显示调用内嵌函数
9+
print("foo() is running")
10+
11+
foo()

python3code/chapter03/weight.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# coding:utf-8
2-
2+
'''
3+
filename: weight.py
4+
'''
35
def weight(g):
46
def cal_mg(m):
57
return m * g

0 commit comments

Comments
 (0)