亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更改 for 循環的前一個條目

更改 for 循環的前一個條目

一只甜甜圈 2023-02-15 16:41:52
是否可以更改 for 循環,在它運行后然后在下一次迭代中返回并更改它?#the code examplescore = 50running = Truewhile 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() == **change**:            #Edit previous loop input because of an error or typo(x should have been z previous iteration) #How would one make this happen?
查看完整描述

1 回答

?
慕標5832272

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)


查看完整回答
反對 回復 2023-02-15
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號