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

xiaoxiao2021-03-01  6

#处理异常 ##使用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()

 

转载请注明原文地址: https://www.6miu.com/read-4150297.html

最新回复(0)