python try catch demo
时间: 2023-10-14 12:27:06 浏览: 95
python demo
好的,以下是一个Python的try catch示例代码:
```python
try:
num1 = int(input("输入被除数: "))
num2 = int(input("输入除数: "))
result = num1 / num2
print("结果为: ", result)
except ZeroDivisionError:
print("除数不能为0")
except ValueError:
print("输入的值必须是整数")
except Exception as e:
print("发生错误: ", e)
```
请问是否满足您的需求?
阅读全文