0
我有一個代碼,我需要找到一個數字的主要因素。在發現主要因素後,我需要知道如何破解我的代碼,所以當它達到1.我剛剛開始使用python進行編碼,並且我還沒有和其他館藏一起使用familiair,所以我想知道是否可以製作一個只打破常規的Python代碼。 NUM達到1python打破嵌套循環與多個if功能
num = int(input("Give me a number:"))
priemgetallen = []
for reeks in range(2, num+1):
print(reeks)
for priemgetal in range(2,reeks):
if reeks % priemgetal != 0:
print(priemgetal)
if num%priemgetal == 0:
print("This is the old num", num)
num = num/priemgetal
print("This is the new num", num)
priemgetallen.append(priemgetal)
if num > 1:
if num%priemgetal == 0:
print("This is the new num", num)
num = num/priemgetal
print("This is the old num", num)
priemgetallen.append(priemgetal)
else:
print(priemgetallen)
break
else:
print("Num stays old")
print(priemgetallen)
就像break語句一樣,你可以返回你的語句。 –