In: Computer Science
We have a class defined for vehicles. Create two new vehicles called car1 and car2. Let car1 to be a red convertible worth $60,000.00 with a name of Fer, and car2 to be a blue van named Jump worth $10,000.00.
# define the Vehicle class
class Vehicle:
name = ""
kind = "car"
color = ""
value = 100.00
def description(self):
print (“Name of car =”,self.name)
print (“Kind of car =”,self.kind)
print (“Color of car =”,self.color)
print (“Value of car =”,self.value)
# test code
car1.description()
car2.description()
Using the program above, add in your own codes in order to complete the program to produce the output as below:
Name of car = Fer
Kind of car = Convertible
Color of car = Red
Value of car = $60,000
Name of car = Jump
Kind of car = Van
Color of car = Blue
Value of car = $10,000
#Python
# define the Vehicle class
class Vehicle:
name = ""
kind = "car"
color = ""
value = 100.00
def description(self):
print ("Name of car
=",self.name)
print ("Kind of car
=",self.kind)
print ("Color of car
=",self.color)
# introduce $ sign and a comma in
value
print ("Value of car
=",'${:,}'.format(self.value))
# define a constructor for the Vehicle class
def
__init__(self,newName,newKind,newColor,newValue):
self.name = newName
self.kind = newKind
self.color = newColor
self.value = newValue
# car1 - a red convertible worth $60,000.00 with a name of
Fer
car1 = Vehicle("Fer","Convertible","Red",60000)
# car2 - a blue van named Jump worth $10,000.00.
car2 = Vehicle("Jump","Van","Blue",10000)
# test code
car1.description()
car2.description()
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~