Python Forum
TypeError: __init__() missing 1 required positional argument: 'successor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: __init__() missing 1 required positional argument: 'successor
#1
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 Sad 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 ... Huh

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
Reply
#2
you set __init__ as follows:
def __init__(self, president, country, elected, successor):
this requires 4 parameters president, country, elected and successor
if you wish to set a default value for successor, write this way:
def __init__(self, president, country, elected, successor=None):
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Missing 1 required positional argument in python code edwinostby 7 9,933 Jan-19-2021, 12:52 PM
Last Post: Serafim
  Missing positional arguments error?? hhydration 2 2,148 Oct-01-2020, 05:33 AM
Last Post: buran
  TypeError: Missing required positional arguments liaisa 7 28,983 Sep-25-2020, 08:16 PM
Last Post: deanhystad
  missing positional argument error programmert 1 2,822 Oct-18-2019, 11:05 AM
Last Post: Larz60+
  missing 1 required positional argument jedmond2 4 6,691 Sep-19-2019, 12:00 PM
Last Post: jefsummers
  missing 1 required positional argument mcgrim 10 19,756 May-07-2019, 09:02 PM
Last Post: Yoriz
  TypeError: __init__() missing 3 required positional arguments Pythonhelp82 6 23,128 Jan-24-2019, 04:25 AM
Last Post: Pythonhelp82
  TypeError: method missing 1 positional argument koolinka 4 5,028 Nov-18-2018, 04:53 PM
Last Post: ichabod801
  another positional argument error (...and executing objects stored in a list) itmustbebunnies 7 4,210 Nov-16-2018, 07:18 PM
Last Post: itmustbebunnies
  Class positional argument error itmustbebunnies 2 2,995 Nov-07-2018, 11:09 AM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020