Created
September 15, 2023 11:43
-
-
Save weihanchen/8fd4343be76556191d427faec150612c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def try_except_finally_example(): | |
try: | |
num1 = int(input("請輸入一個整數: ")) | |
num2 = int(input("請輸入另一個整數: ")) | |
result = num1 / num2 | |
except ZeroDivisionError: | |
print("錯誤:除以零。") | |
except ValueError: | |
print("錯誤:輸入的不是整數。") | |
finally: | |
print("不管是否發生異常,這裡都會執行。") | |
try_except_finally_example() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment