python循环判断异常(异常处理)
2015-07-08 16:34
716 查看
#循环只有在没有异常的情况下才会退出
while True:
try:
x = input('Enter the first number:')
y = input('Enter the second number:')
value = x/y
print 'x/y is ', value
except Exception,e:
print 'Invalid input:',e
print 'Please try again'
else:
break
测试结果:
while True:
try:
x = input('Enter the first number:')
y = input('Enter the second number:')
value = x/y
print 'x/y is ', value
except Exception,e:
print 'Invalid input:',e
print 'Please try again'
else:
break
测试结果:
相关文章推荐
- python 字符串模式匹配
- python调用SOA服务
- python捕捉对象(异常处理)
- python初学-02常用概念
- python初码
- 一句Python命令启动一个Web服务器
- python进阶一:高阶函数
- python六核心编程——条件和循环
- python 通过pywin32获取windows日志
- 【leetcode】Candy(python)
- Python里的string 和 unicode (二)
- Python里的string 和 unicode (一)
- Python实现批量下载图片的方法
- Prototype pattern (Python recipe)
- 纯python实现的web: tornado性能测试以及实际使用解析
- python中的列表(list),字典(dict),字符串(str)的基本操作
- 十分钟搞定pandas
- Python正则表达式-2
- Python正则表达式-1
- Python第三方常用工具、库、框架等