I'm trying to make a class, Player
, and I'd like the user to create objects, say to add to their team.
Every tutorial will have something like this to create new players, say Jordan.
class Player:
def __init__(self, name):
self.name = name
p1 = Player('Jordan')
p2 = Player('Kobe')
But I want the user to have the ability to create new players, and they're not going to code, right? And I would rather the object variable be just the player name, like, "Jordan", or "Kobe".
So if everything was manual, I could say,
jordan = Player('Jordan')
kobe = Player('Kobe')
So to come up with a function to have users create players, what should it look like? And what would the variable be? Any way to get it assigned as the player name? Or at least a serialized number like p1, p2, p3, ...?
def create_player():
new_player = input("Which player would you like to create? ")
name_of_variable_for_player = Player(new_player)
Ok, so follow on question.
What happens when you just have a static variable in the create function?
def create_player():
p = Player(input("What player would you like to make? ")