May-14-2019, 11:55 AM
So right now, I'm trying to loop a line that requires input until a condition is met, but I can't seem to do so.
Essentially, what I want is:
Code asks user how many players are playing: Var (playerAmt)
From there, set a while loop that while 'playerAmt'!= actualPlayers
Ask user for names of each player in relation to playerAmt: Var (playerNames) - e.g. if 3 players are playing, code will repeat input code until it's been asked 3 times, then break out of loop
Which will then added to a list using playerList.append(playerNames)
Edit: The "userAmount" variable was asked before this function runs, which is obviously incorrect, but I have no idea how to remedy this.
Essentially, what I want is:
Code asks user how many players are playing: Var (playerAmt)
From there, set a while loop that while 'playerAmt'!= actualPlayers
Ask user for names of each player in relation to playerAmt: Var (playerNames) - e.g. if 3 players are playing, code will repeat input code until it's been asked 3 times, then break out of loop
Which will then added to a list using playerList.append(playerNames)
def playerNames(): userNun=int(input("Number of players?")) while userAmount != userNun: userNames=input("Please input your names") playerList.append(userNames) random.shuffle(playerList) return playerListI know this code isn't working, as I can't seem to find a way to arrange it in a way as stated above, any help will be appreciated, thanks!
Edit: The "userAmount" variable was asked before this function runs, which is obviously incorrect, but I have no idea how to remedy this.