Python - Unit 6 Exercise from Introduction to Object-Oriented Programming with Python - Error (TypeError: method() takes 1 positional argument but 2 were given)

Vignesh Devendran 6 Reputation points
2021-09-06T10:05:44.963+00:00

I have encountered an error while coding in Python while programming form the unit 6 in introduction to OOP's with Python. I was working with the following code:
class Participant:
def init(self, name):
self.name = name
self.points = 0
self.choice = ""
def choose(self):
self.choice = input("{name}, select rock, paper or scissor: ".format(name= self.name))
print("{name} selects {choice}".format(name=self.name, choice = self.choice))

class GameRound:
def init(self, p1, p2):
p1.choose()
p2.choose()
def compareChoices(self):
print("implement")
def awardPoints(self):
print("implement")

class Game:
def init(self):
self.endGame = False
self.participant = Participant("Spock")
self.secondParticipant = Participant("Kirk")
def start(self):
game_round = GameRound(self.participant, self.secondParticipant)

def checkEndCondition(self):
print("implement")
def determineWinner(self):
print("implement")

game = Game()
game.start()
Then I encountered the an error saying :- AttributeError: 'Game' object has no attribute 'participant'.
Then I tried typing 'participant' in game.start(). But this didn't fix it. Then I tried typing digits, quotation marks, etc.
MY PC SPECIFICATIONS - Windows 10 Home (x64), Python 3.9 (from Microsoft Store) run through Command Prompt.
129509-screenshot-1.png

The above screenshot is the set of errors I have encountered.
6-exercise-game-transitions-with-methods

This is the link of the exercise I was working with. Please help me fix this issue. I also referred this link -typeerror-method-takes-1-positional-argument-but-2-were-given

THANKING YOU.

Community Center Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Sam of Simple Samples 5,546 Reputation points
    2021-09-06T20:37:31.207+00:00

    At the end of that unit is a note saying:

    The solution for this exercise can be found at Continuation query - solution code.

    Go to there. Click on the button for the Raw code. For me, I copied the code to an editor so I can compare what I had to their code. I had:

    def compareChoices(self):
    

    Instead of:

    def compareChoices(self, p1, p2):
    

    Making that correction fixed the problem for me.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.