Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.4 Problem Recording a repair class Car: def __init__(self, vin, brand, model, year): self._vin = vin self._brand = brand self._model = model self._year =

Python 3.4 Problem Recording a repair class Car: def __init__(self, vin, brand, model, year): self._vin = vin self._brand = brand self._model = model self._year = year self._repairs = [] def add_repair(self, repair_desc, repair_cost): self._repairs += [Repair(repair_desc, repair_cost)] def __repr__(self): return 'VIN: ' + self._vin + ' ' + \ ' Brand: ' + self._brand + ' ' + \ ' Model: ' + self._model + ' ' + \ ' Year: ' + str(self._year) + ' '  

if __name__ == '__main__': def reset_car_database(): c01 = Car('XYZ123X', 'Toyota', 'Camry', 2012) c02 = Car('HSY113Y', 'Honda', 'Civic', 2016) c03 = Car('MZJ291E', 'Ford', 'Escape', 2009) c04 = Car('KJD922P', 'Jeep', 'Wrangler', 2011) c05 = Car('TRQ235K', 'Hyundai', 'Sonata', 2017) c06 = Car('JNH47GB', 'Toyota', 'Camry', 2011) c07 = Car('K83JDE3', 'Honda', 'Pilot', 2009) c08 = Car('MCJD83J', 'Hyundai', 'Elantra', 2013) c09 = Car('9EM2JSK', 'Toyota', 'Camry', 2002) c10 = Car('JF83JKS', 'Honda', 'Civic', 2012) c01.add_repair('Broken axle', 2900) c01.add_repair('Punctured tire', 40) c02.add_repair('Cracked windshield', 1000) c04.add_repair('Oil change', 45) c04.add_repair('New clearcoat', 550) c05.add_repair('Punctured tire', 30) c05.add_repair('Cracked windshield', 1000) c06.add_repair('Popped dents', 75) c06.add_repair('Broken headlight', 80) c06.add_repair('Broken taillight', 95) c07.add_repair('Rebuilt engine', 4880) c09.add_repair('Broken headlight', 80) c09.add_repair('Punctured tire', 80) c10.add_repair('Replaced windshield wipers', 125) car_list1 = [c02, c03, c05, c06, c07, c08, c09] car_list2 = [c01, c03, c04, c05, c06, c08, c09, c10] car_list3 = [c03, c04, c08] return car_list1, car_list2, car_list3 

image text in transcribed

These are the instructions and I got this so far:

def record_repair(cars, vin, repair_desc, repair_cost): for car in cars: num = car._vin if num == vin: total_cost = car.add_repair(repair_desc, repair_cost) return total_cost else: return 0 

My code doesn't work. How should I solve the problem?

Part I: Recording a Repair (3 points) Write a function record-repair that records a repair for a car and returns the total cost of all repairs for that car (including the new repair). The function takes four arguments, in this order: cars: a list of Car objects vin: the VIN for the car that we want to record a repair for repair-desc: a description of the repair repair-cost: the cost of the repair (an integer) The function must search the list of Car objects for the car with the given vin, call the add-repair method of the Car class with the given repair desc and repair-cost to record a repair for the car, and then return CSE 101 Spring 2017 Lab #8 Page 2 the new total repair costs for the car. If no Car object is found in the list cars with the given vin, the function should simply return 0 Examples: While looking at the examples in this document, you should have open then provided lab8.py file so that you can see exactly what are the contents of cars1, cars2 and cars 3. Return Value Function Call record repair (carsi, HSY113Y', Punctured tire', 40) 1040 record repair (cars1, MZJ2 91E', Cracked rim' 800) 800 record repair (cars1, XYZ123x', 'Broken mirror', 250) 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

Determine whether the series converges or diverges.

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago