Mar-07-2021, 11:06 PM
Hi guys!
I have a school project. The task is to print three presidents by class and objects using write(), also method __init__ to create presidents with name, country and inauguration date. I have already made a class President with three attributes: name, country and inauguration. That I have done.
But the next task is to print the successor for each president:
"Now you need to modify the program so that President objects also have a attribute successor that holds the object of the next president in the row. For the last president in line, the successor shall have the value None. The class should also have a method setSuccessor(next) that assigns the next president to successor. Example: clinton.Successor(bush)
Now the president is represented by the variable presidents row contains the first president. The rest of the presidents are represented by successor."
So this is what I have wrote so far, but I don't get it
I get this error I wrote in subject. Missing argument successor. But my guess is that thats not only the problem.
Programming Python is so hard, and the task we are given are so difficult I my opinion ...
Appreciate all answers!
I have a school project. The task is to print three presidents by class and objects using write(), also method __init__ to create presidents with name, country and inauguration date. I have already made a class President with three attributes: name, country and inauguration. That I have done.
But the next task is to print the successor for each president:
"Now you need to modify the program so that President objects also have a attribute successor that holds the object of the next president in the row. For the last president in line, the successor shall have the value None. The class should also have a method setSuccessor(next) that assigns the next president to successor. Example: clinton.Successor(bush)
Now the president is represented by the variable presidents row contains the first president. The rest of the presidents are represented by successor."
So this is what I have wrote so far, but I don't get it

Programming Python is so hard, and the task we are given are so difficult I my opinion ...

Appreciate all answers!
# a) class President: def __init__(self, president, country, elected, successor): self.president = president self.country = country self.elected = elected self.successor = successor def write(self): print(self.president,"of the", self.country, "inauguration:", self.elected, self.successor) def __str__(self): return f"{self.president} of the {self.country}, inauguration: {self.elected} {self.successor}" clinton = President("Bill Clinton", "US", "1993") bush = President("George W Bush", "US", "2001") obama = President("Barack Obama", "US", "2009") print(clinton) print(bush) print(obama) presidents = [President("Bill Clinton", "US", "1993"), President("George W Bush", "US", "2001"), President("Barack Obama", "US", "2009")] # b) def setSuccessor(next): successor=next clinton.successor(bush) bush.sucessor(obama) obama.successor = None