Created
September 15, 2023 11:41
-
-
Save weihanchen/f2b8bcb9a900cd2a1bf703abbb4aa0bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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_else_example(): | |
try: | |
num1 = int(input("請輸入一個整數: ")) | |
num2 = int(input("請輸入另一個整數: ")) | |
result = num1 / num2 | |
except ZeroDivisionError: | |
print("錯誤:除以零。") | |
except ValueError: | |
print("錯誤:輸入的不是整數。") | |
else: | |
print("沒有例外時顯示結果:", result) | |
try_except_else_example() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment