python3--异常处理及习题
来源:互联网 发布:2017笔记本推荐 知乎 编辑:程序博客网 时间:2024/06/08 08:43
#异常处理try..except...
#打开一个不存在的文件
try:
with open('non_exist.txt',mode='r') as f1:
print('file opend!')
f1.close()
except:
print('file is not exist!')
print('DONE!')
#使用异常处理猜数字游戏,输入非整数,抛出异常
import random
flag = False
while(flag == False):
try:
result = random.randint(1,101)
number = int(input('input you number:'))
if number == result:
print('bingo!')
flag = True
elif number > result:
print('you have big number!')
else:
print('you have small number!')
except:
print('please input integer!')
#打开一个不存在的文件
try:
with open('non_exist.txt',mode='r') as f1:
print('file opend!')
f1.close()
except:
print('file is not exist!')
print('DONE!')
#使用异常处理猜数字游戏,输入非整数,抛出异常
import random
flag = False
while(flag == False):
try:
result = random.randint(1,101)
number = int(input('input you number:'))
if number == result:
print('bingo!')
flag = True
elif number > result:
print('you have big number!')
else:
print('you have small number!')
except:
print('please input integer!')
阅读全文
0 0
- python3--异常处理及习题
- python3 异常及异常处理
- Java异常处理习题
- Python3.2 --- 异常处理
- Python3 的异常处理
- Python3 的异常处理
- python3的异常处理
- Python3 异常处理
- Python3 异常处理
- Python3 异常处理
- Python3之异常处理
- python3 异常处理
- python3.x的异常处理
- Python3:异常处理,try...except
- Python3.X中的异常处理
- Python3学习(29)--异常处理
- java面向对象-异常处理-习题
- Python3.2官方文档翻译--异常处理
- C++常见操作符的重载
- Centos7 hadoop集群 mysql、hive、sentry安装验证
- 面向对象设计的SOLID原则
- VS2013/MFC基于对话框编程:文本超链接
- STL-容器
- python3--异常处理及习题
- 1858: [Scoi2010]序列操作
- 算法题/两个栈实现队列
- Hbase安装与使用
- 带涨跌箭头的柱形图
- Number Sequence
- 144. Binary Tree Preorder Traversal 【先序遍历 + 栈模拟递归】
- 滤波
- poj 3233 Matrix Power Series