如何执行库存程序

时间:2018-06-02 06:52:55

标签: python

我还在学习python。我正在尝试编写一个开发汽车库存的程序。我正在创建一个automobile课程,将由经销商用作车辆库存计划。汽车类中应包含以下属性:

private string make
private string model
private string color
private int year
private int mileage

如何执行此操作并提示输入。它没有这样做。

class Automobile():
    __make = ""
    __model = ""
    __color = ""
    __year = 0
    __mileage = 0


    def __init__(self, make = None, model = None, color = None, year = None, mileage = None):
        self.make = make
        self.model = model
        self.color = color
        self.year = year
        self.mileage = mileage

    def add_vehicle(self):
        auto = Automobile()
        vehicle_file = open('vehicle.txt', 'a')
        make = input("Enter make: ")
        model = input("Enter model: ")
        color = input("Enter color: ")
        year = input("Enter year: ")
        mileage = input("Enter mileage: ")

        vehicles = Automobile(make, model, color, year, mileage)
        vehicle_list = [vehicles.make, vehicles.model, vehicles.color, vehicles.year, vehicles.mileage]

        for item in vehicle_list:
            vehicle_file.write("%s\t" % item)
        vehicle_file.write("\n")
        vehicle_file.close()
        print("Your record has been succesfully added to the inventory")

    def delete_vehicle(self):
        del_rec = input("Enter record to delete: ")

        with open("vehicle.txt","r+") as f:
            new_f = f.readlines()
            f.seek(0)
            for line in new_f:
                if del_rec not in line:
                    f.write(line)
            f.truncate()
        print("Succesfully deleted record from inventory")

    def set_make(self, make):
        self.make = make

    def get_make(self):
        return self.make

    def set_model(self, model):
        self.model = model

    def get_model(self):
        return self.model

    def set_color(self, color):
        self.color = color

    def get_color(self):
        return self.color

    def set_year(self, year):
        self.year = year

    def get_year(self):
        return self.year

    def set_mileage(self, mileage):
        self.mileage = mileage

    def get_mileage(self):
        return self.mileage

0 个答案:

没有答案