I have 2 classes, one inherits from the other. I need instances of WOFPlayer to take 1 required parameter - name, 2 optional and instances of WOFComputerPlayer to take 2 required parameters - name and difficulty and 2 optional as in the WOFPlayer. How do I do that?
Here's what I have tried
class WOFPlayer:
def __init__(self, name, prizeMoney = 0, prizes = []):
self.name = name
self.prizeMoney = prizeMoney
self.prizes = prizes[:]
class WOFComputerPlayer(WOFPlayer):
def __init__(self, difficulty):
WOFPlayer.__init__(self, name, prizeMoney = 0, prizes = [])
self.difficulty = difficulty
Thanks in advance
WOFPlayerwhich you would not like to be inherited inWOFComputerPlayer, you can set them asprivateinstances. To do so, just put two underlines before the name of the instances. For example,__name.WOFComputerPlayer.__init__is supposed to accept bothnameanddifficultyas parameters, then the first thing is that they should both appear between the parentheses that appear afterdef __init__. Otherwise, I don't see what the actual question is.