标签:inter ffffff finally try 报错信息 ges keyboard raw_input input
#!/usr/bin/python
#coding:utf-8
try:
x=int(raw_input("请输入用户名:"))
print 3/x
except KeyboardInterrupt:
print "你输入了crtl+c,请重试"
except EOFError:
print "你输入了ctrl+d,请重试"
except ValueError:
print "你输入的不是数字"
except ZeroDivisionError,e: #把自带报错存入变量
print "除数不能输入0:",e #打印自带报错信息
else:
print "没毛病" #不出错执行
finally:
print "Game Over" #出不出错都执行
#!/usr/bin/python
#coding:utf-8
x=raw_input("xxx你爱我吗(y/n)?")
try:
if x!=‘y‘:
raise ValueError,"答案不对,请重试"
except ValueError,e:
print e
else:
print "OK"
标签:inter ffffff finally try 报错信息 ges keyboard raw_input input
原文地址:http://blog.51cto.com/13587189/2070540