Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何避免在满足条件之前推进循环?_Python_List_For Loop - Fatal编程技术网

Python 如何避免在满足条件之前推进循环?

Python 如何避免在满足条件之前推进循环?,python,list,for-loop,Python,List,For Loop,我编写了以下程序: numb= ["First", "Second", "Third"] players=[] n = '' score=[] for i in numb: print("Type the score of the name of the", i, "player:") answer = n = str(input(' ')) players.append(d) for a in players: for b in numb:

我编写了以下程序:

numb= ["First", "Second", "Third"]
players=[]
n = ''
score=[]

for i in numb:
    print("Type the score of the name of the", i, "player:")
    answer = n = str(input(' '))
    players.append(d)

for a in players:
    for b in numb:
        a = int(input("Type the", b, "score of", a))
        if a!=0:
            score.append(a)
        else:
我想避免在numb:中为b推进内部循环
,只要a是0。

例如:如果第一个分数为0,程序将再次打印“键入第一个分数…”。

我想这就是您想要的:

for a in players:
   for b in numb:
       done = False
       while not done:
           a = int(input(f"Type the {b} score of {a}"))
           if a :
               score.append(a)
               done = True
done
开始为False,为True时中断并转到下一个列表元素


离题:我给你的代码添加了一些PEP8,希望你喜欢

在python>=3.8中,您可以使用新添加的:

for a in players:
    for b in numb:
        while (a := int(input(f"Type the {b} score of {a}")) == 0:
            pass
        score.append(a)