错误的程序及结果:

image

image 

image

 

解决1:

guess = int(raw_input('请输入一个整数:'.decode('utf-8').encode('gbk')))

image

 

解决2:

guess = int(raw_input(unicode('请输入一个整数:','utf-8').encode('gbk')))

image

此处python 版本 2.7.11,编译器 sublime 3

 

注意:

python 中出现中文一般需要加前缀 u 或 U 用来避免乱码,但只对 print 有效,对 raw_input 无效(或者我没有找到解决方法)

posted on 2016-03-28 17:57  Amy-Lee  阅读(1710)  评论(0)    收藏  举报