Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help with this python assignment Preliminaries For this lab you will be wor

ID: 3812583 • Letter: N

Question

need help with this python assignment

Preliminaries For this lab you will be working with the following classes 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 In' +N Model self model An Year str (self. year) In' +N Total Repairs: str(self total repairs 0) class Repair: def init (self desc cost) self desc desc self cost cost def repr. (self) return self desc str (self cost)

Explanation / Answer



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 : '+self._year+' '+
               '   Repairs : '+str(self._repairs)+' '

class Repair:
   def __init__(self,desc,cost):
       self._desc = desc
       self._cost = cost
      
   def __repr__(self):
       return self._desc+' : $'+ str(self._cost)
      

def record_repair(cars , vin, repair_desc, repair_cost):
   cost = 0
   for car in cars:
       if(str(car._vin) == str(vin)):
           car.add_repair(repair_desc,repair_cost)
           repairs = car._repairs
           for repair in repairs:
               cost += repair._cost
   return cost
          
  
car = Car("sa3f","adfs","adfsa","afsa")  
car.add_repair("wheel",5)
cars = []
cars.append(car)
car2 = Car("saf",'ok',"adfsa","afsa")
car2.add_repair("string",15)
cars.append(car2)


cost = record_repair(cars,'saf',"all",50)
print cost