首页 > 编程语言 > 详细

Python学习(2)

时间:2014-04-11 08:31:41      阅读:392      评论:0      收藏:0      [点我收藏+]

总感觉把标题写成"Python学习(2)"有些不合适,但是没想到其他的,就暂且这样吧

今天写了个程序但是在DOS窗口和IDEL窗口调试的结果不一样,有些郁闷~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python 
#coding=utf-8 
#python version:2.7.3
#system:windows 7
evilxr=raw_input("Evilxr:")
screen_width=80
text_width=len(evilxr)
box_width=text_width+2
left_margin=(screen_width - box_width) // 2
print
print ‘ ‘ *left_margin + ‘+‘ + ‘-‘ * (box_width-2) + ‘+‘
print ‘ ‘ *left_margin + ‘|‘ + ‘ ‘ *  text_width   + ‘|‘
print ‘ ‘ *left_margin + ‘|‘ +        evilxr       + ‘|‘
print ‘ ‘ *left_margin + ‘|‘ + ‘ ‘ *  text_width   + ‘|‘
print ‘ ‘ *left_margin + ‘+‘ + ‘-‘ * (box_width-2) + ‘+‘
print

  bubuko.com,布布扣

    bubuko.com,布布扣        bubuko.com,布布扣

补充:

修改后代码如下,感谢Fooying的帮助:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python 
#coding=utf-8 
#python version:2.7.3
#system:windows 7
evilxr=raw_input("Evilxr:")
try:
    evilxr = evilxr.decode(‘utf-8‘).encode(‘gbk‘)
except UnicodeDecodeError:
    pass
screen_width=80
box_width=text_width+2
left_margin=(screen_width - box_width) // 2
print
print ‘ ‘ *left_margin + ‘+‘ + ‘-‘ * (box_width-2) + ‘+‘
print ‘ ‘ *left_margin + ‘|‘ + ‘ ‘ *  text_width   + ‘|‘
print ‘ ‘ *left_margin + ‘|‘ +        evilxr       + ‘|‘
print ‘ ‘ *left_margin + ‘|‘ + ‘ ‘ *  text_width   + ‘|‘
print ‘ ‘ *left_margin + ‘+‘ + ‘-‘ * (box_width-2) + ‘+‘
print

Fooying推荐pep8规范:http://baid.ws/cCBn 

Python学习(2),布布扣,bubuko.com

Python学习(2)

原文:http://www.cnblogs.com/evilxr/p/3657769.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!