Design a simple Python class for a Car Your class should hav

Design a simple Python class for a Car. Your class should have the following methods: _init_(self, mfr, price): creates a car object (e.g. mazda with a price of $15000) getMfr(self): returns the make of the car getPrice(self): returns the price of the car Populate a list with three Car objects of your choice with different manufacturers and prices. Then perform two different sorts of the list using the sort() method - one based on Mfr and one based on price. Print out both versions of the list.

Solution

#!/usr/bin/env python
import operator

class Car(object):
    def __init__(self, mfr, price):
      
        self.mfr = mfr
       self.price = price

    def set_mfr(self, mfr=mazda):
        self.mfr = mfr

    def set_price(self, price =15000):
       self.price = price

    def set_mfr(self, mfr=honda):
          self.mfr = mfr

    def set_price(self, price =35000):
       self.price = price

   def set_mfr(self, mfr=swift):
         self.mfr = mfr

    def set_price(self, price =24000):
       self.price = price

   Car.getMfr(self)
   Car.getPrice(self)
   Car.sort()

      

  

 Design a simple Python class for a Car. Your class should have the following methods: _init_(self, mfr, price): creates a car object (e.g. mazda with a price o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site