below in the Attendee class you define setters
which will set values to your data attributes (variables)
whenever an object is created and the user input the data
and you also define getters which are used to retrieve those data
on demand
the last line with str will print the object state as a string
class Attendee:
def __init__(self, fName, lName, email):
self.fName = fName
self.lName = lName
self.email = email
def set_fName(self, fName):
self.__fName = fName
def set_lName(self, lName):
self.__lName = lName
def set_email(self, email):
self.__email = email
def get_fName(self, fName):
return self.__fName
def get_lName(self, lName):
return self.__lName
def get_email(self, email):
return self.__email
def __str__(self):
return "First name: " + self.__fName + "\nLast name: " + self.__lName + "\nEmail: " + self.__email
below is an example of a main program which asks for user input
and creates a class object (of New_attendee class)
I added a dictionary which is first created empty ( = {} )
and each entry is stored in the dictionary
def main():
NewAttendee = {}
again = 'y'
while again == 'y':
fName = input("First name: ")
lName = input("Last name: ")
email = input("Email: ")
entry = Attendee(fName,lName, email)
if fName not in NewAttendee:
NewAttendee[fName] = entry
print('The new attendee has been added')
else:
print('That name already exists.')
again = input('Do you want to add a new attendee? \'y\' for yes -->')
main()
Hope that helps!
PS: I didnt put the str (object state as a string) into action
newObjectNameto be the name of the variable? That is, ifnewObjectName = "bob"thenbob = Attendee(...)?