python -- fruitful function and void function

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


 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值