File tree Expand file tree Collapse file tree 8 files changed +146
-0
lines changed Expand file tree Collapse file tree 8 files changed +146
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 14:41:50
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ import math
9
+
10
+
11
+ def area (radius ):
12
+ """ 返回一个圆的面积
13
+ 用给定的半径。
14
+ 例如:
15
+ >>> area(5.5)
16
+ 95.0331777711
17
+ """
18
+ return math .pi * radius ** 2
19
+
20
+ print (area (5.5 ))
21
+ print (area .__doc__ )
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 15:05:22
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ name = 'Jack'
9
+
10
+
11
+ def say_hello ():
12
+ print ('Hello ' + name + ' !' )
13
+
14
+
15
+ def change_name (new_name ):
16
+ global name
17
+ name = new_name
18
+ say_hello ()
19
+ change_name ('chenhao' )
20
+ say_hello ()
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 15:02:52
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ name = 'Jack'
9
+
10
+
11
+ def say_hello ():
12
+ print ('Hello ' + name + ' !' )
13
+
14
+
15
+ def change_name (new_name ):
16
+ name = new_name
17
+ say_hello ()
18
+ change_name ('chenhao' )
19
+ say_hello ()
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 15:17:04
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+
9
+ def greet (name , greeting = 'Hello' ):
10
+ print (greeting + ' ' + name + '!' )
11
+ greet ('chenhao' , 'hi' )
12
+ greet ('chenhao' )
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 15:50:58
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ import shapes
9
+ # print(dir(shapes))
10
+
11
+ shapes .rectangle (2 , 3 )
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 15:57:43
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ from shapes import *
9
+
10
+ rectangle (2 , 3 )
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 15:32:03
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ """
9
+ 函数的集合
10
+ 打印基本形状
11
+ """
12
+ CHAR = '*'
13
+
14
+
15
+ def rectangle (heigh , width ):
16
+ """打印矩形."""
17
+ for row in range (heigh ):
18
+ for col in range (width ):
19
+ print (CHAR ),
20
+ print ('' )
21
+
22
+
23
+ def square (side ):
24
+ """打印一个正方形."""
25
+ rectangle (side , side )
26
+
27
+
28
+ def triangle (heigh ):
29
+ """打印直角三角形."""
30
+ for row in range (heigh ):
31
+ for col in range (1 , row + 2 ):
32
+ print (CHAR ),
33
+ print ('' )
34
+
35
+ # rectangle(2, 3)
36
+ # square(3)
37
+ # triangle(3)
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-17 15:24:42
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+
9
+ def shop (where = 'store' ,
10
+ what = 'pasta' ,
11
+ howmuch = '10 pounds' ):
12
+ print ('I want you to go to the ' + where )
13
+ print ('and buy ' + howmuch + ' of ' + what + '.' )
14
+ shop ()
15
+
16
+ shop (where = 'xianju' , howmuch = '30 pounds' )
You can’t perform that action at this time.
0 commit comments