如何重复 while 循环但不从头开始
现在,我已经学习了python大约2周了。我想解决此代码。
number = 0
while True:
input_1 = int(input('First Number: '))
number += 1
if input_1 == 1:
input_2 = int(input('Second Number: '))
number += 2
if input_2 == 2:
input_3 = int(input('Third Number: '))
number += 3
if input_3 == 3:
break
else:
number -= 6
continue
else:
number -= 3
continue
else:
number -= 1
continue
print(number)
因此,基本上,我想在循环时重复启动,例如当im input_2中的im和条件进入时,我希望代码再次循环到Input_2。感谢您的所有答案
right now i have been learning python like 2 weeks. and i want to solve this code.
number = 0
while True:
input_1 = int(input('First Number: '))
number += 1
if input_1 == 1:
input_2 = int(input('Second Number: '))
number += 2
if input_2 == 2:
input_3 = int(input('Third Number: '))
number += 3
if input_3 == 3:
break
else:
number -= 6
continue
else:
number -= 3
continue
else:
number -= 1
continue
print(number)
so basically i want to repeat while loop not for beginning, as example when im in input_2 and the condition get in to else, i want the code is looping to input_2 again. thanku for all of ur answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您所有的循环都具有相似的行为,所以最好的方法是根据当前阶段循环循环,而不是嵌套循环:
Because all your loops share similar behavior, the best approach to this would be to loop through variables based on the current stage rather than have nested loops: