Python学习(2)

总感觉把标题写成"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

  Python学习(2)

    Python学习(2)        Python学习(2)

补充:

修改后代码如下,感谢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)

上一篇:20个优秀的 JavaScript 键盘事件处理库


下一篇:Java简单工厂模式