Ask how many players there are.
()
| 53 | |
| 54 | |
| 55 | def getPlayerNames(): |
| 56 | """Ask how many players there are.""" |
| 57 | while True: # Keep asking until the player enters a number. |
| 58 | print('How many players are there? Max:', MAX_NUMBER_OF_PLAYERS) |
| 59 | response = input('> ') |
| 60 | if response.isdecimal(): |
| 61 | numPlayers = int(response) |
| 62 | if 1 < numPlayers <= MAX_NUMBER_OF_PLAYERS: |
| 63 | break |
| 64 | print('Enter a number between 2 and', MAX_NUMBER_OF_PLAYERS) |
| 65 | |
| 66 | # Enter the names of each player: |
| 67 | playerNames = [] # List of the string player names. |
| 68 | for i in range(1, numPlayers + 1): |
| 69 | while True: # Keep asking until the player enters a valid name. |
| 70 | print('Enter player #' + str(i) + "'s name:") |
| 71 | name = input('> ') |
| 72 | if len(name) == 0: |
| 73 | print('Please enter a name.') |
| 74 | elif name in playerNames: |
| 75 | print('Choose a name that has not already been used.') |
| 76 | else: |
| 77 | break # The entered name is acceptable. |
| 78 | |
| 79 | playerNames.append(name) |
| 80 | return playerNames |
| 81 | |
| 82 | |
| 83 | def getLegs(players): |