I am attempting to create a Linked list of appointments, but when I run test code it gives me a type error saying that I am missing 3 positional arguments. I would imagine the solution is something simple but I've been tinkering with it for awhile and cannot figure it out.
from datetime import datetime
class VaccList:
class Appointment:
def __init__(self, name, age, city, date):
assert type(name) is str, 'name variable must be a string'
assert type(age) is int, 'age variable must be a integer'
assert type(city) is str, 'city variable must be a string'
assert type(date) is datetime, 'date variable must be a datetime object'
assert name != None, 'name variable cannot be empty'
assert age >= 18 and age <= 100, 'age must be between 18 and 100'
# ADD 6 asserts. 4 for the types and name cannot be empty,
# and age must be between 18 and 100
self.name = name
self.age = age
self.city = city
self.date = date
self.confirmed = False
self.next = None
def __str__(self):
s = "Appointment for " + self.name + " on " + str(self.date) + " age:" + str(
self.age) + " city:" + self.city
if self.confirmed:
s += " (confirmed)"
else:
s += " (unconfirmed)"
return s
def __init__(self):
self.head = None
self.tail = None
def isEmpty(self):
return self.head is None
def print(self):
'''
Print all the appointments, one per line. Print a blank line after the last one.
If the list is empty, print a line saying the Appointment List is empty.
'''
pass
def append(self, newAppt):
''' Given a pointer to an Appointment object, tack it onto the end.
If the list was empty, then make sure to set both pointers!
This is only used for appointments that are canceled or completed,
since we want the active list to remain sorted by date.
'''
assert type(newAppt) is VaccList.Appointment, "append() requires a pointer to an Appointment object."
# Note, no loop is needed!
newnode = VaccList.Appointment(newAppt)
if self.head is None:
self.head = newnode
else:
newnode.next = self.head
self.head = newnode
if __name__ == "__main__":
active = VaccList()
appt = VaccList.Appointment("Henry", 72, "Buffalo", datetime(2021, 5, 1, 12, 0, 0))
active.append(appt)
Below is the following error I keep encountering:
Traceback (most recent call last):
File "/Users/nicholas/Downloads/SHELL/vacclist.py", line 152, in <module>
active.append(appt)
File "/Users/nicholas/Downloads/SHELL/vacclist.py", line 54, in append
newnode = VaccList.Appointment(newAppt)
TypeError: __init__() missing 3 required positional arguments: 'age', 'city', and 'date'
Any help on this is truly appreciated as I am in the beginning stages of learning python.