我面臨以下錯誤。一個小時前,我正在處理 Jupyter 的互動式會話。再次打開它后,我試圖回到會話,我發現 Jupyter 無法再顯示代碼的輸出。
我試圖再次重新啟動 Anaconda 和 Jupyter 會話,問題仍然存在,只是for loop,而其他部分似乎作業正常。有沒有人遇到過同樣的問題?誰能建議我該怎么做?
div = [5,7]
div[0]
for num in range(1,42):
if num == 13:
continue
if num%div[0]==0:
print(num, 'the number is divisible for 5')
if num%div[1]==0:
print(num, 'the number is divisible for 7')
if num%div[0]==0 and num%div[1]==1:
print(num, 'the number is divisible for both 5 and
uj5u.com熱心網友回復:
你的代碼太嵌套了。如果一個數字不是 13 的倍數,則根本不會發生任何事情,因為程式永遠不會到達任何其他if陳述句,如果它是 13 的倍數,那么它會命中該continue陳述句。在任何一種情況下,都不會列印任何內容。你想要更多類似的東西:
div = [5,7]
div[0]
for num in range(1,42):
if num == 13:
continue
if num%div[0]==0:
print(num, 'the number is divisible for 5')
if num%div[1]==0:
print(num, 'the number is divisible for 7')
if num%div[0]==0 and num%div[1]==1:
print(num, 'the number is divisible for both 5 and 7')
這給出了輸出——錯誤的輸出但仍然輸出。你有一個錯字num%div[1]==1。由于這是明顯的功課,我將把其余的除錯留作練習。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/445058.html
