Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have an assignment I am working on for Python 3 Programming class that I am almost to the finish line but need a little

I have an assignment I am working on for Python 3 Programming class that I am almost to the finish line but need a little help with suggestions or tips to clean the code up and shorten the length of code. Here are the assignment instructions and I have attached the pics of my Komodo editor showing the code I have so far. It will output what we're looking for but just need some suggestions on how to shorten it but still make it function correctly.

  • Code 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:

  • constructor
  • 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.

  • Your final program submission materials must include your source code and screenshots of the application executing the application and the results.

class automobile:

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

self.make=make

self.model=model

self.color=color

self.year=year

self.mileage=mileage

def display(self):

print(f"Auto Make={self.make}")

print(f"Auto Model={self.model}")

print(f"Auto Color={self.color}")

print(f"Auto Purchased Year={self.year}")

print(f"Auto Mileage={self.mileage}")

Auto_data=list()

def Inventory():

print(f" Inventory")

print(" a-Add Auto r-Remove Auto u-Update Auto Information")

print(" d-Display Automobiles in Inventory s-Save All Automobile Information Into File q-Quit")

def add():

make=input("Enter Auto Make=")

model=input("Enter Auto Model=")

color=input("Enter Auto Color=")

year=int(input("Enter Auto Purchased Year="))

mileage=int(input("Enter Auto Mileage="))

Auto_data.append(automobile(make,model,color,year,mileage))

def display():

i=0

for vehicle_info in Auto_data:

print(f" Auto Number={i+1} ")

vehicle_info.display()

i+=1

def remove():

flag=0

auto_number=-1

auto_del=0

make=input("Enter Auto Make To Delete=")

for vehicle_info in Auto_data:

auto_number+=1

if vehicle_info.automobile__make==make:

flag=1

auto_del=auto_number

if flag==0:

print(f" Auto Make Not Found")

else:

Auto_data.pop(auto_del)

print(f" Auto Delete From Inventory")

def update():

flag=0

auto_number=-1

auto_del=0

make=input("Enter Auto Make to Update Auto: ")

for vehicle_info in Auto_data:

auto_number+=1

if vehicle_info._automobile__make==make:

flag=1

auto_del=auto_number

if flag==0:

print(f" Auto Make Not Found")

else:

for vehicle_info in Auto_data:

if vehcile_info._automobile__make==make:

new_make=input("Enter Updated Auto Make=")

new_model=input("Enter Updated Auto Model=")

new_color=input("Enter Updated Auto Color=")

new_year=int(input("Enter Updated Auto Purchased Year="))

new_mileage=int(input("Enter Updated Auto Mileage="))

vehicle_info.__automobile__make=new_make

vehicle_info.__automobile__model=new_model

vehicle_info.__automobile__color=new_color

vehicle_info.__automobile__year=new_year

vehicle_info.__automobile__mileage=new_mileage

print(f" Auto Update")

def save():

f = open("ouputAuto.txt" , "w")

i=0

for vehicle_info in Auto_data:

f.write(f" Auto Number={i+1}")

f.write(f" Auto Make={vehicle_info._automobile__makel}")

f.write(f" Auto Model={vehicle_info._automobile__model}")

f.write(f" Auto Color={vehicle_info._automobile__color}")

f.write(f" Auto Purchased Year={vehicle_info._automobile__year}")

f.write(f" Auto Mileage={vehicle_info._automobile__mileage}")

i+=1

print(f" File outputAuto.txt is created and all automobile data is saved")

f.close()

def exit():

quit()

def default():

print(" Invalid Choice")

# dictionary terms of all functions

tasks = {

'a': add,

'r': remove,

'u': update,

's': save,

'q': exit,

'd': display

}

def select_Task(choice):

return tasks.get(choice, default)()

while True:

Inventory()

ts=input(" Select Task =")

select_Task(ts)

ts=print("-------------------------")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions