---- fruitful function: A function that returns a value.
---- void function: A function that doesn’t return a value.
linux下python进入,敲python即可,退出输入:exit()
查看Tkinter是否安装:To see if you have Tkinter, type python on the Linux command line.
Then at the python prompt, type
>>>import Tkinter
Or in Python 3
>>> import tkinter
If you have Tkinter, Python will not print an error message and you can go on to the next section.
Otherwise you will see something like this:
ImportError: No module named Tkinter
In that case, you have to install Tkinter. On Ubuntu, you can run
sudo apt-get install python-tk
Or for Python 3
sudo apt-get install python python3-tk
Or use the Synaptic Package Manager to install "python-tk".
1 #!/usr/bin/python
2 def do_twice(f):
3 f() # does not have semicolon
4 f()
5
6 def do_four(f):
7 do_twice(f)
8 do_twice(f)
9
10 def print_beam():
11 print('+----'),
12 def print_post():
13 print('| '),
14 def print_beams():
15 do_twice(print_beam)
16 print('+')
17 def print_posts():
18 do_twice(print_post)
19 print('|')
20
21 def print_row():
22 print_beams()
23 do_four(print_posts)
24 def print_graph():
25 do_twice(print_row)
26 print_beams()
27
28 print_graph()
1 #!/usr/bin/python
2 def do_twice(f):
3 f()
4 f()
5 def do_four(f):
6 do_twice(f)
7 do_twice(f)
8 def one_four_one(f,g,h):
9 f()
10 do_four(g)
11 h()
12 def print_plus():
13 print('+'),
14 def print_dash():
15 print('-'),
16 def print_bar():
17 print('|'),
18 def print_space():
19 print(' '),
20 def print_end():
21 print
22 def nothing():
23 "do nothing"
24
25 def print_one_beam():
26 one_four_one(nothing,print_dash,print_plus)
27
28 def print_four_beams():
29 one_four_one(print_plus,print_one_beam,print_end)
30
31 def print_one_post():
32 one_four_one(nothing,print_space,print_bar)
33
34 def print_four_posts():
35 one_four_one(print_bar,print_one_post,print_end)
36
37 def print_row():
38 one_four_one(nothing,print_four_posts,print_four_beams)
39 def print_grid():
40 one_four_one(print_four_beams,print_row,nothing)
41
42 print_grid()