[Python]《从入门到实践》第十章-读取、写入文件和处理异常

#处理异常
##使用try-except代码块
try:
    print(5/0)
except ZeroDivisionError:
    print("You can't divide by zero!")
##使用else输出正确结果
print("Division:")
print("Enter 'q' to quit.")

while True:
    first_number=input("\nFirst number: ")
    if first_number == 'q':
        break
    second_number=input("\nSecond number: ")
    try:
        answer=int(first_number)/int(second_number)
    except ZeroDivisionError:
        print("You can't divide by 0!")
    else:
        print(answer)
        print("Enter 'q' to quit.")
        
#存储数据
import json
#json.dump()与json.load()

 

你可能感兴趣的:(Python)