MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / getPlayerNames

Function getPlayerNames

src/gamesbyexample/ghostleglottery.py:55–80  ·  view source on GitHub ↗

Ask how many players there are.

()

Source from the content-addressed store, hash-verified

53
54
55def 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
83def getLegs(players):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected