question

VigneshDevendran-3510 avatar image
0 Votes"
VigneshDevendran-3510 asked VigneshDevendran-3510 edited

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

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.


not-supported-azure
screenshot-1.png (141.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am learning Python too so I took the course too. I got the same thing. I assume it is their mistake. We can submit it as an issue but that won't help us. I will try to figure it out. If we cannot figure it out one of us can submit a question to a Python forum but I will try to figure it out first.

129751-t.jpg


1 Vote 1 ·
t.jpg (24.9 KiB)

1 Answer

SimpleSamples avatar image
0 Votes"
SimpleSamples answered VigneshDevendran-3510 edited

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried it but this shows another error now :-AttributeError: 'Game' object has no attribute 'participant'129931-screenshot-2.png


Please check my last step. There's something to be typed in "game.start()"

0 Votes 0 ·
screenshot-2.png (118.6 KiB)