1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mote1985 [20]
2 years ago
12

In this exercise, you will get some practice with the __add__ method by implementing it for a class called ContactBook. This cla

ss represents a collection of names and phone numbers. ContactBook stores its information as a dictionary, where the key is a name and the value is a phone number or group of phone numbers. The keys and values in this dictionary are stored as strings. When printed, a ContactBook might look like this:
Computers and Technology
1 answer:
Wittaler [7]2 years ago
8 0

Answer:

class ContactBook():

   def __init__(self):

       self.contacts ={}

   def __repr__(self):

       return str(self.contacts)

   def add_contact(self,name,number):

       self.contacts[name] = number

   def __add__(self, other):

       new_contact = ContactBook()

       other_contact = other.contacts.keys()

       for name,num in self.contacts.items():

           if name in other_contact:

               new_contact.add_contact(name,num or other_contact[name])

           else:

               new_contact.add_contact(name,num)

       for name,num in other.contacts.items():

           if name not in self.contacts:

               new_contact.add_contact(name, num)

       return new_contact-

cb1 = ContactBook()

cb2 = ContactBook()

cb1.add_contact('Jonathan','444-555-6666')

cb1.add_contact('Puneet','333-555-7777')

cb2.add_contact('Jonathan','222-555-8888')

cb2.add_contact('Lisa','111-555-9999')

print(cb1)

print(cb2)

cb3 = cb1+cb2

print(cb3)

Explanation:

The ContactBook class holds the contact details of an instance of the class. The class has three magic methods the '__repr__', '__init__', and the '__add__' which is the focus of the code. The add magic method in the class adds the contact book (dictionary) of two added object instance and returns a new class with the contact details of both operand instances which is denoted as self and other.

You might be interested in
It is possible to play older console games such as those written for the nintendo game boy or sega genesis on a personal compute
timurjin [86]
Emulator««««that is the answer
5 0
3 years ago
Describe and list advantages and disadvantages of each of the following backup types:
crimeas [40]

Answer:

Full back up

It creates complete copy of the source of data. This feature made it to the best  back  up with good speed of recovery of the data and  simplicity.However, because it  is needed for backing up  of  a lot of data, it is time consuming process,Besides it also  disturbs the routine application of  the technologist infrastructure. In addition large capacity storage is needed  for the  storage of  the large volume of back up with each new creation.

Incremental back up: back up work at high speed thus saves time, Little storage capacity is needed. This type of back up can be run as  many time as wished.

However, the restoration of data takes time, due to the time spent for restoration of initial back up and the incremental.

Differential Back up has very fast back up operation, because it only requires two pieces of back up.This is however slower compare to the Incremental.

The selective back up enable selection of certain type of file or folders for back up.

it can only be used to back up folders only when important data  are needed only.Thus the  storage capacity is low.

CPD eliminates back up window and reduces the recovery point objective.However, it has issue of compatibility with the resources to back up.,it is also expensive because its solutions are disk based.

Cloud based is affordable and save cost,It is easier to access. it is efficient,it can be access remotely for convenience.

However, Internet sources and some bandwidth must be available for access., always depends on third party providers,There is also problems encountered when switching providers.

Explanation:

8 0
3 years ago
File names should describe what is in the file in a few words
JulijaS [17]

Answer

File names should describe the content of the file.

Explanation

File names are set of words  which are used to uniquely identify computer files which are stored in a file system. This helps one to know the contents of the file which you want to find. When you name these file names you use necessary characters you use descriptive words so that you dont have hard times when searching for them. The naming also is determined by the file system you are using because different systems impose different restrictions on the length of the file names and the allowed characters within file names.

3 0
3 years ago
Nothin to see here just browsin
velikii [3]

Answer:

What????

What does that mean??????????????????????????????????

4 0
2 years ago
Maria is an experienced programmer who has worked on different projects. she was recently promoted to be a software development
aleksklad [387]
Maria would have to have experience of being a leader, confident,and would have to be serious about her job. She would have to control everybody on the team and keep them on task.
8 0
3 years ago
Read 2 more answers
Other questions:
  • 1. An Excel file is called a workbook?<br> A) True<br> B) False
    6·2 answers
  • zeroIt is a function that takes one argument and returns no value. The function stores the value 0 back into the parameter. x is
    8·1 answer
  • Which term refers to the data stored in computer memory on which the processor applies to program instructions
    11·1 answer
  • while investigating the settings on your SOHO router, you find two IP address reported on the devices's routing table, which is
    5·1 answer
  • Identify a characteristic of electronic meeting systems.
    10·1 answer
  • Who is your favorite smite god in Hi-Rez’s “Smite”
    14·1 answer
  • What are the steps to customize a slide show?
    10·2 answers
  • HELP PLS QUICK TRUE OR FALSE QUESTION
    7·2 answers
  • Suppose cell C5 contains the formula =B$6+C1.
    6·1 answer
  • If you select one slice of pie in a pie chart, you have selected a ____
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!