I did not understand the necessity of the "while " statement and the statement "if player:" in this code -
def get_players_list():
"""() -> list of [str, int] list
Prompt the player(s) to enter their names and return a list of player info
as a two-item list with name and score, respectively.
"""
players = []
player = input('Enter player 1 name: ')
while player.strip() or not players: ##**#why is this needed?**
player = player.strip()
if player in players:
print("A player by that name is already playing.")
if player: **# what is the function of this command#**
players.append([player, 0])
if players:
print('Leave a blank player name to begin playing.')
player = input('Enter player {num} name: '.format(num=len(players) + 1))
return players
Aucun commentaire:
Enregistrer un commentaire