1

I wrote the following program:

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:

I want to avoid advancing the inner loop for b in numb: as long as a is 0. For example: if the first score is 0, the program will print again "Type the first score...".

misha
  • 777
  • 1
  • 9
  • 21
Fabix
  • 321
  • 1
  • 2
  • 17

2 Answers2

2

I think that that is it what you want:

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 starts False, and when it is True while breaks and goes to next list element

off topic: I add some PEP8 to your code, hope you enjoy!

0

In python >= 3.8 you could use the newly added Walrus operator:

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