# 上學期期末考解答 [**提問表單**](https://forms.gle/z4dPC1JPV6uA2q9w7) --- ```python= running = True while running: for event in pygame.event.get(): if event == 'QUIT': running = False pygame.quit() ``` ## a003. 兩光法師占卜術 [**題目連結**](https://zerojudge.tw/ShowProblem?problemid=a003) [**參考詳解連結**](https://steam.oxxostudio.tw/category/python/zerojudge/a003.html) ## a038. 數字翻轉 [**題目連結**](https://zerojudge.tw/ShowProblem?problemid=a038) [**參考詳解連結**](https://steam.oxxostudio.tw/category/python/zerojudge/a038.html) ## b558. 求數列第 n 項 [**題目連結**](https://zerojudge.tw/ShowProblem?problemid=b558) [**補充-無限輸入**](https://steam.oxxostudio.tw/category/python/basic/try-except.html) >之前在寫的時候,不需要加try&except的原因是,那是我們手動強制停止程式,停止後一定會報錯,而在zerojudge中為了避免程式報錯必須加上try&except。 [**參考詳解連結**](https://steam.oxxostudio.tw/category/python/zerojudge/b558.html) ## b513. 判斷質數-商競103 [**題目連結**](https://zerojudge.tw/ShowProblem?problemid=b513) **詳解** ```python= # 開一個列表儲存所有合數 L_composite = [] # 先判斷出3~66000內的所有合數 for i in range(3, 66000): for j in range(2, i): # 只需判斷2~該數的平方根內有沒有其因數 if j > i**0.5: break elif i % j == 0: L_composite.append(i) break # 輸入幾個數 n = int(input()) for i in range(n): a = int(input()) # 判斷是否為合數 if a not in L_composite: print('Y') else: print('N') ``` ## k254. 拍七 (Seven) [**題目連結**](https://zerojudge.tw/ShowProblem?problemid=k254) **詳解** ```python= # 開一個列表儲存所有合數 L_composite = [] # 先判斷出3~66000內的所有合數 for i in range(3, 66000): for j in range(2, i): # 只需判斷2~該數的平方根內有沒有其因數 if j > i**0.5: break elif i % j == 0: L_composite.append(i) break # 輸入幾個數 n = int(input()) for i in range(n): a = int(input()) # 判斷是否為合數 if a not in L_composite: print('Y') else: print('N') ``` ## a417. 螺旋矩陣 [**題目連結**](https://zerojudge.tw/ShowProblem?problemid=a417) [**參考詳解連結**](https://steam.oxxostudio.tw/category/python/zerojudge/a417.html) ## 補充資料 **推薦網站:**[**W3Schools**](https://www.w3schools.com/) **推薦網站:**[**STEAM 教育學習網**](https://steam.oxxostudio.tw/category/python/) >這個網站推薦大家在找zerojudge的python練習題的時候,可以優先選裡面有詳解的來做,這樣就算不懂也還有詳解可以馬上參考!