Python 如何停止整个循环?
我在下面的python循环中遇到了一个问题 它不会在totalout=4时立即停止,但只有当scorein的整个循环结束时才会停止。(即第三个循环) 例如,如果2号中的totalout=4,它将运行循环直到达到10Python 如何停止整个循环?,python,Python,我在下面的python循环中遇到了一个问题 它不会在totalout=4时立即停止,但只有当scorein的整个循环结束时才会停止。(即第三个循环) 例如,如果2号中的totalout=4,它将运行循环直到达到10 #global value totalturn=0 totalscorein=0 totalout=0 def main numberofturn=int(input("Number of score:")) no_turn=['1','2','3','4','5
#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("")
#全局值
totalturn=0
totalscorein=0
totalout=0
def总管
numberofturn=int(输入(“分数:”)
无转弯=['1'、'2'、'3'、'4'、'5'、'6'、'7'、'8'、'9'、'10']
#while循环条件
totalturn时,尝试将和
运算符更改为或
。那似乎是你想要的
而totalscore是否希望中断
从3个循环中中断?我想你是从问题的标题来判断的
在这种情况下,由于它是函数的结尾,您可以将break
替换为return
while循环之前的totalscore、numberofscore和totalout的值是多少?totalscore
,numberofscore
不被声明,您的第一行应该使用赋值而不是冒号(加上列表
不是变量名的好选择)。对不起,我已经做了更改。你应该发布你的实际代码。这里有很多错误,因此此代码甚至无法运行。这是因为循环的顺序错误吗?我是python新手…我想做的是:首先,程序在turn1下运行,然后在turn1下运行,循环10分,然后在Turn2下运行,循环10分,如果分数为o'和totalouts=4,我想停止整个循环,包括转弯循环,但现在我只能在分数达到10时停止得分循环,但转弯循环没有停止谢谢是的,我想打破所有3个循环,它正在工作!!非常感谢:)