First time posting here, let me apologize ahead of time if this is not the correct format.. Anyway, I am new to programming and I am working on a school assignment to design a vehicle inventory system in Python (assignment details below). The code seems to be working as it should. I am questioning the 'update vehicle' function I defined outside of the class, whether it would make more sense to change to a class method. Or any other feedback anyone has. Thanks. Create a final program that meets the requirements outlined below.
Assignment: Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class:
- private string make
- private string model
- private string color
- private int year
- private int mileage
Your program should have appropriate methods such as:
- add a new vehicle
- remove a vehicle
- update vehicle attributes
At the end of your program, it should allow the user to output all vehicle inventory to a text file.
class Automobile: def __init__(self): self.make = " " self.model = " " self.color = " " self.year = 0 self.mileage = 0 def add_vehicle(self): self.year = int(input("Enter year: ")) self.make = input("Enter make: ") self.model = input("Enter model: ") self.color = input("Enter color: ") self.mileage = int(input("Enter mileage: ")) def __str__(self): return('%d %s %s Color: %s Mileage: %d' % (self.year, self.make, self.model, self. color, self.mileage)) vehicle_list =  def edit(vehicle_list): pos = int(input('Enter the position of the vehicle to edit: ')) new_vehicle = car.add_vehicle() new_vehicle = car.__str__() vehicle_list[pos-1] = new_vehicle print('Vehicle was updated') user=True while user: print (""" 1.Add a Vehicle 2.Delete a Vehicle 3.View Inventory 4.Update Inventory 5.Export Inventory 6.Quit """) ans=input("What would you like to do? ") if ans=="1": car = Automobile() car.add_vehicle() vehicle_list.append(car.__str__()) elif ans=="2": for i in vehicle_list: vehicle_list.pop(int(input('Enter position of vehicle to remove: '))) print('Successfully removed vehicle') elif ans=="3": print(vehicle_list) elif ans=="4": edit(vehicle_list) elif ans=='5': f = open('vehicle_inv.txt', 'w') f.write(str(vehicle_list)) f.close() else: print('try again')