Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 7 Write a function add _ owners that will match cars with their owners based on a dictionary passed as a parameter. The dictionary

Task 7
Write a function add_owners that will match cars with their owners based on a dictionary passed as a parameter. The dictionary uses owners (Person objects) as keys and tuples of Car objects they own, as values. You may/should reuse the previously developed function get_address to retrieve Persons addresses. Note that this function does not print or return anything, its role is to modify existing objects.
Example usage:
>>
houses =[]
h1= House('123 Happy St. Blackwood')
h2= House('6 Agnes Av. Aldinga')
h3= House('8 Daw St. Aldinga')
h4= House('23 Oak St. Blackwood')
h5= House('61 Gorge Av. Aldinga')
h6= House('81 Waterman St. Aldinga')
c1= Car('Ford','Mustang',2)
c2= Car('Ford','Fiesta',4)
c3= Car('Toyota','Camry',2)
c4= Car('Mazda','Cx-9',6)
c5= Car('Mazda','Cx-5',5)
c6= Car('Mitsubishi','Colt',12)
c7= Car('Toyota','Corolla',2)
p1= Person('Jim',28)
p2= Person('Ashley',31)
p3= Person('Cleo',21)
p4= Person('Jessica',18)
p5= Person('Adam',19)
p6= Person('Andrew',34)
p7= Person('Jake',20)
p8= Person('Joshua',17)
p9= Person('Amica',27)
p10= Person('Helen',34)
p11= Person('Barney',29)
p12= Person('Sandra',30)
p13= Person('John',25)
p14= Person('Patrick',26)
p15= Person('Sammy',19)
h1.add_car(c1,c2)
h2.add_car(c3)
h3.add_car(c4)
h4.add_car(c5,c6,c7)
h5.add_car(c8)
h6.add_car(c9,c10)
h1.add_inhabitant(p1,p2,p3,p4)
h2.add_inhabitant(p5,p6)
h3.add_inhabitant(p7,p8,p9)
h4.add_inhabitant(p10)
h5.add_inhabitant(p11,p12)
h6.add_inhabitant(p13,p14,p15)
houses.extend([h1,h2,h3,h4,h5,h6])
d ={p1:(c1,c2),p2:(c3,c4),p3:(c6,c7,c1), p5:c5}
add_owners(houses,d)
print(c1.get_owners_list())
print(c4.get_owners_list())
print(c5.get_owners_list())
output:
[['Jim','123 Happy St. Blackwood'],['Cleo','123 Happy St. Blackwood']]
[['Ashley','123 Happy St. Blackwood']]
[['Adam','6 Agnes Av. Aldinga']]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What has been your desire for leadership in CVS Health?

Answered: 1 week ago