我在下面的循环中遇到了python问题。
一旦totalout = 4,它就不会停止,但只有当scorein的整个循环结束时才会停止。 (即第三环)
例如,如果totalout = 4 in scorein number 2,则运行循环直到达到10
#global value
totalturn=0
totalscorein=0
totalout=0
def main
numberofturn=int(input("Number of score:"))
no_turn=['1','2','3','4','5','6','7','8','9','10']
#while loop condition
while totalturn<numberofturn and totalout<10:
#increasement
totalscore+=1
#for loop for score
for t in range(1,numberofturn+1):
turns=s*1
print("\n\n\nThe turn"+no_turn[t]+":",turns)
#for loop for number to appear from list
for c in range (10):
#list for random number to appear
numscore = ['1','2','3','4','5','6','7','8','9','o']
#random choice from numscore list to appear
from random import choice
scorein=choice(numscore)
print ("\n\nScores :",scorein)
if scorein.isdigit():
totalscorein=totalscorein+int(scorein)
if scorein.isalpha():
totalout+=1
if totalturn==numberofturn:
print("\nTotal turn played:",totalturn)
elif totalout==4:
print("\nTotal turns played",totalturn)
break
else:
print("")
答案 0 :(得分:1)
您希望break
突破3个循环吗?我想你是从问题的标题来判断的
在这种情况下,由于它是函数的结尾,您只需将break
替换为return
答案 1 :(得分:0)
尝试将and
运算符更改为or
。这似乎是你想要的。
while totalscore<numberofscore or totalout<10: