I'm currently working on this,
Design a class Car. This class has the following attributes: maker, model, and price The Car class should have methods to return the current values of these attributes. In addition, this class has a method update_price to change the price attribute value.
Design a class called Dealer. This class has the following attributes: address and inventory. The inventory attribute is a list of Car objects. The Dealer class should have methods to add a car object to the inventory, remove a car object from the inventory (car removal should be done based on car model), and update the price of a certain car model. This class also has a method that shows the entire inventory and a method that calculates the total value of all cars in the inventory.
In the main function, the program creates a Dealer object, adds multiple cars to the inventory, and shows the current inventory. Then the program removes a car model from the inventory and updates the price for a given car model. At the end, the program displays the entire inventory and the total value of all cars currently in the inventory.
But when I run my code I get
TypeError: descriptor 'append' requires a 'list' object but received a 'tuple'
And I have no idea how to fix this
class Car:
def __init__(self, maker, model, price):
self.__maker=maker
self.__model=model
self.__price=price
def get_model(self):
return self.__model
def get_maker(self):
return self.__maker
def get_price(self):
return self.__price
def create_list(list):
maker=input('Enter Car maker: ')
model=input('Enter Car model: ')
price=float(input('Enter Car price: $'))
account=(maker, model, price)
list.append(account)
def update_price(self):
self.__price=price
return self.__update_price
class Dealer():
def __init__(address, inventory):
self.__inventory=inventory
self.__address=address
def update_price(list):
model=input('Enter car model: ')
account=Car(maker, model, price)
found='false'
for model in list:
if account.get_model() == model:
account.append(price)
found=='true'
if found == 'false':
print('Model Not Found')
return account
def show_inventory(list):
show_inventory=print(account)
def calculate_total_value(list):
print(sum(self.__account.price))
def remove_car(list):
model=input('Model for removal')
found = 'false'
for model in list:
if account.get_model() ==model:
account.remove(model)
found =='true'
if found =='false':
print('Model Not Found')
def get_address(address):
self.__address=address
return self.__address
def main():
address=input('Enter address: ')
account_list=[]
counter=1
manytimes=float(input('How many cars to add? '))
while counter<=manytimes:
counter=counter+1
create_list(list)
show_inventory(account_list)
remove_car(account_list)
show_inventory(list)
update_price(account_list)
show_inventory(account_list)
calculate_total_value(account_list)
main()