Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i n python Create two files, one named person.py and the other named contacts.py . Each file should have its own class Person and Contacts
n python Create two files, one named person.py and the other named contacts.py Each file should have its own class Person and Contacts respectively. Most of the heavy work will be in the Person class. Thus, let's dive in it first and then move to the Contacts class. The Person class should have a constructor initializer method that takes three arguments otherwise, testinitializingaperson will not succeed.
A string that holds the person's name and is stored in self.name.
A dictionary holds all the person's numbers where the key is a string, and the value is an integer. The given dictionary should be stored in a variable named self.numbers.
A string that holds the person's email address and should be saved in self.email.
Before you start implementing the project requirement, we highly recommend that you override the method repr to help you debug your code. Remember from the lecture, that the repr is meant to help developers understand the object's content more easily. You can implement it however you want. In fact, this is not a requirement, thus it is up to you whether to have it or not.
The first method you have to implement in the Person class is defining what we mean when we say does Person Person We must define the eq relationship between two Person objects to check if we have duplicates later. We say that Person equal Person if and only if all their attributes selfname, self.numbers, and self.email are the same. Please note that self.numbers are equal if they have the same information regardless of their order. By implementing these features you should have the first three tests passing now.
Now that we can check if two Person objects are equal to validate the duplication, we need to define the comparison operators and for sorting. In any contacts list, we would like to have sorted contacts. By default, people think of sorting their contact based on peoples' names. Thus, to be able to sort many different Person instances, we need to define the comparison operators ltlegt and ge A person is a person if the name of perosnname is less than the name of personname alphabetically. For example, we know that the string "Apple" is less than "Banana" because the letter A comes before the letter B in the English alphabet. The same rule should be applied to the other comparison operators and
By now you should be passing all the test cases in testperosn.py except for the last one. The Person class should override str to enable a beautified printing. Simply we need to print the name of the Perosn in an instant, then within each newline, we want to print all the numbers they have after a tab. The str should print a string similar to the one given below we use t and
to achieve this outcome
p PersonAhmadprimary: 'mobile': "ahmad@institution.edu"
printp
Ahmad:
primary:
mobile:
email: ahmad@institution.edu
Test the Person class until you feel confident. Do not move to the Contacts class until all tests and more from you if possible are passed successfully. Otherwise, you could be confused as to from which class an error you are getting is coming from.
Start implementing and testing the Contacts class. The Contacts should extend the builtin list class. Otherwise, you would have to implement all the methods already provided by list.
The Contacts class should NOT have an initializer. That is it uses its parent initializer.
A method you have to add, however, is the countduplicates method which takes only self as an argument and returns an integer. This will be highly dependent on your correct implementation of Person.eq The count duplicate as given by the name should count how many of its elements are the same. For example, if we have the list a b a a the count of duplicates is even if the value a was observed three times, we say that a itself has a duplicate thus the count is In your case, you will be considering a person's object instead of the letters a or b
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started