
Python 入門指南 5.0
exercise0808.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # 設定狀態變數 state = True # 例外處理 try: my_variable = 1 / 1 except: # 重新設定狀態變數 state = False else: # 沒發生錯誤的情況 my_variable = 0 finally: # 依狀態變數印出結果 if state: print(my_variable) else: print(state) # 檔名: exercise0808.py # 說明:《Python入門指南》的練習 # 網站: http://kaiching.org # 作者: 張凱慶 # 時間: 2023 年 8 月 |
