所以我在这里有这段代码:
count = 1
if count < 5:
print ("If 5 rounds have passed, enter any other key: ")
nextr = str(input("Do you want to continue to the next round?(1)" + "\n"))
if nextr in ("1", "(1)"):
count += 1
continue
while count == 5:
break
我想知道:我怎么能做这个计数控制的循环,而不是每次都恢复到1。我希望程序能够完成一次游戏,询问用户是否要继续游戏,然后在打破之前再进行4次,然后再显示最终得分。任何帮助非常感谢!
我不确定你在寻找什么,但它可能有所帮助。
print ("If 5 rounds have passed, enter any other key")
count = 1
while count <= 5:
nextr = (input("Do you want to continue to the next round?(Yes/No)"))
print ("count = ",count)
if nextr.lower() in ("y", "yes"):
count += 1
或者像这样的东西:
import time
def round_5():
count = 1
while count <= 5:
print ("Count = ",count)
count += 1
time.sleep(1)
nextr = "y"
print ("If 5 rounds have passed, enter any other key:")
while nextr.lower() in ("yes","y"):
round_5()
nextr = (input("Do you want to continue to the next round?(Yes/No)"))
print ("Thank you, have a nice day")