0

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()
Adama
  • 31
  • 1
  • 1
  • 5
  • 1
    You passed the `list` type instead of an actual list to `create_list`. – user2357112 Nov 17 '17 at 00:40
  • Possible duplicate of [how to add value to a tuple?](https://stackoverflow.com/questions/4913397/how-to-add-value-to-a-tuple) – Nir Alfasi Nov 17 '17 at 00:42
  • See how to create a [mcve] – Peter Wood Nov 17 '17 at 00:43
  • 1
    You never assigned the variable `list` before calling `create_list(list)`. So it's using the global variable, which is the `list` type. You should avoid using variables that are the same as standard Python types or functions. – Barmar Nov 17 '17 at 00:55
  • I guess it was inevitable that as more CS programs switch from Java to Python, that we will be seeing more and more graduates writing Java in Python... – juanpa.arrivillaga Nov 17 '17 at 01:19

1 Answers1

0

Looks like wherever that error is occuring, you're trying to append something to a tuple which is immutable, meaning it can't be changed (in this case, you can't append something to it). A tuple is very similar to a list in that in can store values and be accessed through an index (starting at 0). Wherever you're trying to append something, make sure you're using a list and not a tuple. If it is a tuple, you can convert it to a list using list(tuple_name) and then you should be able to append to it.

ayc.19
  • 98
  • 1
  • 7