I'am trying to create a definition that assigns objects in a list to variables but unfortunately it is not working:
when I try to print player_1
(as in the last step) it gives me a
NameError
Any suggestion or feedbacks on how to make the definition shorter or better is always welcome. The whole project( it is till the beginning) is on https://github.com/ahmadkurdo/project---a
If you have time and look at it and give me some feedback on it would be appreciated.
def assign_players(list_of_names):
if len(list_of_names) == 2:
player_1 = list_of_names[0]
player_2 = list_of_names[1]
elif len(list_of_names) == 3:
player_1 = list_of_names[0]
player_2 = list_of_names[1]
player_3 = list_of_names[2]
elif len(list_of_names) == 4:
player_1 = list_of_names[0]
player_2 = list_of_names[1]
player_3 = list_of_names[2]
player_4 = list_of_names[3]
elif len(list_of_names) == 5:
player_1 = list_of_names[0]
player_2 = list_of_names[1]
player_3 = list_of_names[2]
player_4 = list_of_names[3]
player_5 = list_of_names[4]
elif len(list_of_names) == 6:
player_1 = list_of_names[0]
player_2 = list_of_names[1]
player_3 = list_of_names[2]
player_4 = list_of_names[3]
player_5 = list_of_names[4]
player_6 = list_of_names[5]
number_of_players = int(input('How many players are playing? '))
list_of_players = []
while number_of_players > 0:
name_player = input('What is your name ')
list_of_players.append(name_player)
number_of_players = number_of_players - 1
assign_players(list_of_players)
print(player_1)