1. 程式人生 > >python之再學習----簡單的異常

python之再學習----簡單的異常

lena input 直接 ase ber one rod can 跳過

# filename:python3.4.py
# author:super
# date:2018-03-04

# try except 的時候 要把具體的except 內容打印出來
# 如果不想做任何處理 可以在except 後面加上pass 就直接跳過

try:
5/0
except ZeroDivisionError:
print("you can not /0")

print("put ‘q‘ is quit")
print("please input two number:")

while True:
firstnumber = input("\nplease input the firstnumber:")
if firstnumber == ‘q‘:
break
secondnumber = input("please input the second number:")
if secondnumber == ‘q‘:
break
try:
result = int(firstnumber) / int(secondnumber)
print(result)
except ZeroDivisionError:
pass
# print("the secondnumber could not be 0")

python之再學習----簡單的異常