Solution: Extend class "User" to our needs
Completion requirements

UML class and object diagram
The code is devided here into two files.
Good practice is to outsource class definitions into a separate file that has the same name as the class itself:
User.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class User: # class definition def __init__(self, surname, firstname, dateOfBirth): # constructor self.__surname = surname # private properties/attributes self.__firstname = firstname self.__password = firstname[0] + surname[0] + dateOfBirth # assembling of initial password self.__dateOfBirth = dateOfBirth self.__username = surname def getSurname(self): # getter methods return self.__surname def getFirstname(self): return self.__firstname def getPassword(self): return self.__password def getDateOfBirth(self): return self.__dateOfBirth def getUsername(self): return self.__username |
The creation of objects and method calls in a second file:
testUser.py
1 2 3 4 5 6 7 | from User import User # Import from User.py in same directory the class User user1 = User("Miller","Sam","22.11.2004") # Creation of objects user1 and user2 user2 = User("Smith","Jake","13.02.2003") print(user1.getPassword()) # call of methods and output of return values print(user2.getUsername()) |
The output
SM22.11.2004
Smith
Last modified: Monday, 13 March 2023, 8:50 AM