1 回答

TA貢獻1966條經驗 獲得超4個贊
我不認為 Loop 可以回退一次或幾次迭代。問題在于您希望它返回的迭代次數。盡管可以通過反轉操作來實現您的用例,但您正在這樣做。
#the code example
score = 50
running = True
while running:
for rounds in range(0, 6):
for rounds in range(0, 6):
if input() == x:
score - 3
print(score)
elif input() == y:
score - 2
print(score)
elif input() == z:
score - 1
print(score)
elif input() == undoX:
score + 3
print(score)
elif input() == undoY:
score + 2
print(score)
elif input() == undoZ:
score + 1
print(score)
實現它的粗略方法是 undoX(一次操作反轉)、undoX2(兩次操作反轉)等。 input() 的更多數據類型未知;如果它是 Integer 而不是 'undoX' 可以用 '-x' 代替。如果您想在撤消操作后保持迭代次數不變,而不是將 range(0,6) 更改為 range(0,iterations) 并寫入修改后的案例;
elif input() == undoX:
score + 3
iterations+1 //To keep no. of iterations intact with every undoOperation
print(score)
添加回答
舉報