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
Information to develop a project network is collected from the.
Kryger [21]

Information to develop a project network is collected from the work breakdown structure

<h3>Work breakdown structure </h3>

Work breakdown structure (WBS)  is a structure showing the steps needed to be taken so as to complete a project.

WBS is presented in visual format and it is usually arranged based on hierarchy.

Information to develop a project network is collected from the work breakdown structure

Find out more on Work breakdown structure at: brainly.com/question/6197566

7 0
2 years ago
Krystal recorded her times for all her cross-country meets this season. To sort her data showing the lowest times first, what wi
devlian [24]
Sort ascending would be the correct one, since you are going from the lowest value to the highest
3 0
3 years ago
Read 2 more answers
The Internet of Things (IoT) is a concept with emphasis on machine-to-machine communications to describe a more complex system t
VLD [36.1K]

Answer:

IoE(Information of Everything)  is the correct answer to the following question.

Explanation:

The following answer is correct because it is the concept that process, data, people and also Internet of Things brings together by which the network connection become more valuable and more compatible as compared to before and also it can extend the IoT(Internet of Things).

So, that's why the following answer is correct.

8 0
3 years ago
____________ describes major components that comprise a system, their relationships, and the information the components exchange
inysia [295]

Answer: Software Architecture

Explanation:

Architecture of a software depicts the basic structure of a software system. Software architecture also describes how the structure of a system behaves and creates such structures, where each structure is consists of software components, relations between these components and the characteristics of these components and relations. It gives an abstraction of a system while hiding its implementation details. It provides description about how the elements of a system interact with each other. For example Service Oriented Architecture (SOA) is a software architectural approach in  which the different application components provide services to other components over the network. IT is a collection of services that communicate with each other. These services integrate into distinct software systems which belong to different business domains.

3 0
3 years ago
Help!! me!! plsssssssssssssssssssssssssssssssssss
Maslowich

Answer:

e,f,g, and h

Explanation:

5 0
2 years ago
Other questions:
  • What will be the output of the following Python code? class A: def test1(self): print(" test of A called ") class B(A): def test
    15·1 answer
  • Anusha wants to use her computer,rather than handwriting the information on her notepad,to analyze her monthly expenses to make
    14·1 answer
  • Write a program to randomly fill an array of float of 10 elements (use the rand() function and make sure to use #include ) in ma
    11·1 answer
  • The physical parts of the computer are known as?
    14·1 answer
  • Write a procedure ConvertToBinary that takes an input as a number from 0 to 16 (including 0 but not 16) and converts it to a bin
    11·1 answer
  • Which of the following are valid variable names? Select 2 options.
    14·1 answer
  • What is the output by the code system.out.print(8-4+2);
    13·1 answer
  • 2. Explain the difference between a JMP instruction and CALL instruction
    6·1 answer
  • Who has more Tanks? Russia or USA? You get ti right and you get BRAINLIEST
    12·2 answers
  • What are 3 of the most important things about internet safety that you would recommend and why
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!