Hi I am trying to call instance of a my class but don't know how to do that, at this stage it only works if I pre specify everything in newContact and ignores class AddContact. I would like to be able to new contacts to the list maybe? Please help.
My code:
class People():
def __init__(self, name, surname, age, mobile_no, home_no):
self.name = name
self.surname = surname
self.age = age
self.mobile_no = mobile_no
self.home_no = home_no
def DisplayContacts(self):
print("First Name: \t", self.name)
print("Surname: \t", self.surname)
print("Age: \t", self.age)
print("Mobile Number: \t", self.mobile_no)
print("Home Number: \t", self.home_no)
class AddContact():
newname = str(input("First name: \t"))
newsurname = str(input("Surname: \t"))
newage = int(input("Age: \t"))
newmobile_no = int(input("Mobile Number: \t"))
newhome_no = int(input("Home Number: \t"))
newContact = People(newname, newsurname, newage, newmobile_no, newhome_no)
newContact = People()
for p in newContact():
p.DisplayContacts()
newContactis a "Person", the name "People" is confusing as it is not a collection.__call__method, but doesn't appear to be what you're trying to do here.