0
我一直在創建一個組合計算器,這是我很難創建的東西。我經常試圖解決的問題是處理我的代碼中的任何無限循環。程序一直運行 - 無限循環
oglist = ["a","b","c","d"]
combocounter = 3
lists = {}
comboloop = True
combolist = ["lol"]
pendinglist = ["lol"]
for x in range(0, combocounter):
lists["list" + str(x)] = ["lol"]
def loop(counter1):
global recursion1
global recursion2
if len(lists["list" + str(counter1)]) == 0:
lists["list" + str(counter1 - 1)] = lists["list" + str(counter1 - 1)][1:]
print(lists)
recursion1 = True
recursion2 = True
else:
lists["list" + str(counter1 + 1)] = lists["list" + str(counter1)][1:]
print(lists)
recursion2 = False
return
def startingloop():
global recursion1
if len(lists["list0"]) == 0:
comboloop = False
else:
lists["list1"] = lists["list0"][1:]
print(lists)
recursion1 = False
return
def endingloop():
global counter2
global recursion2
if len(lists["list2"]) == 0:
lists["list1"] = lists["list1"][1:]
print(lists)
recursion2 = True
else:
combolist[counter2] = lists["list0"][0]
for y in range(1, combocounter):
combolist[counter2] = combolist[counter2] + lists["list" + str(y)][0]
combolist.append("lol")
lists["list2"] = lists["list2"][1:]
counter2 += 1
print(lists)
print(combolist)
return
lists["list0"] = oglist
counter2 = 0
while comboloop == True:
startingloop()
while recursion1 == False:
loop(1)
while recursion2 == False:
endingloop()
combolist.remove("lol")
print(combolist)
我已經放在一大堆的打印功能: print(lists)
和print(combolist)
。 當我運行它,列表和combolist不斷更新和打印。然後停止打印,但我的程序不斷運行。它也從來沒有達到
combolist.remove("lol")
print(combolist)
我經歷了努力遵循我的代碼的邏輯來發現任何問題,但我沒有。我的代碼中不斷循環着什麼?