Question

I have this py program and I need assistance using it. I am using Visual Studio and I need to know how to:

  1. Add a new vehicle
  2. Delete a vehicle
  3. Update vehicle attributes
  4. Print out inventory

Here is the code:

1 2 import uuid from datetime import datetime class automobile: 3 4 5 6 7 8 9 def _init__(self,make: str, model: str,color: s

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import uuid
from datetime import datetime


class automobile:

    # setting up the constructor with default aruguments
    # default argument can be removed, the all the parameter 
    # should be passed with constructor invocation.
    def __init__(self, make="", model="", color="", year=0, mileage=0):
        self.__id = uuid.uuid1().hex
        self.__make = make
        self.__model = model
        self.__color = color
        self.__year = year
        self.__mileage = mileage
        self.__createdate = datetime.now().strftime("%d-%m-%y %H:%M:%S")

    def add_vehicle(self, inventoryObj):
        inventoryObj.append(self)
    
    def remove_vehicle(self, inventoryObj):
        inventoryObj.remove(self)

    def set_make(self, make):
        self.__make = make
    
    def set_model(self, model):
        self.__model = model
    
    def set_color(self, color):
        self.__color = color

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

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

    def __str__(self):
        return '{}, {}, {}, {}, {}, {}, {}'.format(self.__id, self.__make, self.__model, self.__color, self.__year, self.__mileage, self.__createdate)
    

# creating an empty list to store vehicle content
myVehicleList = []

# creating a vehicle object and printing the same
tom_car = automobile("Toyota", "Fortuner", "White", 2014, 10)
print tom_car

# creating an empty object and adding details using the set functions
bob_car = automobile()
bob_car.set_make("Mercedes")
bob_car.set_model("4matic")
bob_car.set_color("black")
bob_car.set_year(2019)
bob_car.set_mileage(8)
print bob_car

# adding the created objects to the list
tom_car.add_vehicle(myVehicleList)
bob_car.add_vehicle(myVehicleList)

# printing the list elements
print myVehicleList[0]
print myVehicleList[1]
Add a comment
Know the answer?
Add Answer to:
I have this py program and I need assistance using it. I am using Visual Studio...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have to write a program where the program prints a deck of cards. instead of having your regula...

    I have to write a program where the program prints a deck of cards. instead of having your regular suits and numbers the program will use a value for a number, id will be either rock, paper, or scissors, and the coin will be heads or tails. print example: 2 of rock heads. If the user is enters 1 the program will print out 30 of the print example and arrange them by there values. if the user enters 2...

  • 9p This is for Python I need help. Pet #pet.py mName mAge class Pet: + __init__(name,...

    9p This is for Python I need help. Pet #pet.py mName mAge class Pet: + __init__(name, age) + getName + getAge0 def init (self, name, age): self.mName = name self.mAge = age Dog Cat def getName(self): return self.mName mSize mColor + __init__(name, age,size) + getSize() + momCommento + getDog Years() +_init__(name, age,color) + getColor + pretty Factor + getCatYears def getAge(self): return self.mAge #dog.py import pet #cat.py import pet class Dog (pet. Pet): class Cat (pet. Pet): def init (self,...

  • I NEED THIS PROGRAM COMPLETE WITH THE INPUT ALREADY IN IT. I HAVE NO TIME LEFT...

    I NEED THIS PROGRAM COMPLETE WITH THE INPUT ALREADY IN IT. I HAVE NO TIME LEFT TO GET IT DONE AND IT'S BEEN KICKING MY BEHIND FOR THE PAST FEW DAYS. THIS IS MY FINAL PROGRAM AND I HAVE NO CLUE ABOUT WHAT I'M DOING. SO, IF SOME WILL...WILL YOU PLEASE DO THE PROGRAM WITH THE INPUT ALREADY IN IT...I JUST WANT TO BE ABLE TO COPY PASTE AND RUN IT. I WOULD APPRECIATE IT A HECK OF A LOT....

  • I NEED A CORRECT ANSWER THIS TIME PLEASE.THIS IS MY fourth TIME POSTING THIS QUESTION (Inheritance)...

    I NEED A CORRECT ANSWER THIS TIME PLEASE.THIS IS MY fourth TIME POSTING THIS QUESTION (Inheritance) Please write a general class named Vehicle which contains make, model, color, year, mileage, weight and type information. Using the inheritance please write another class for gas vehicle (GasVehicle) and electric vehicles (ElectricVehicle). The GasVehicle class has an attribute named fuel tank capacity. However, the ElectricVehicle class has an energy storage in kwh. All the above classes must contains a method named print_vehicle_info which...

  • Problem: I am trying to implement a binary search function in Visual Studio 2019 using C#....

    Problem: I am trying to implement a binary search function in Visual Studio 2019 using C#. This is my first program in C# and I translated it from Java. In this program, I am to carry out the same 10,000,000 unsuccessful searches for eight different-sized arrays, namely arrays of sizes, 128, 512, 2048, 8192, 32768, 131072, 524288, and 2,097,152. I need to measure each of the three programs and the time it takes to do the 10,000,000 searches for each...

  • I need this in java please Create an automobile class that will be used by a...

    I need this in java please 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: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...

  • For my computer class I have to create a program that deals with making and searching...

    For my computer class I have to create a program that deals with making and searching tweets. I am done with the program but keep getting the error below when I try the first option in the shell. Can someone please explain this error and show me how to fix it in my code below? Thanks! twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...

  • C++ using visual studio. I need to make a dice rolling mechanic. When the dice falls...

    C++ using visual studio. I need to make a dice rolling mechanic. When the dice falls on 1 it will display L, 2 will display R, 3 will display C and the remaining numbers will display A dot I am suppossed to use the code shown here in order to make it #include <ctime> srand(time(NULL)); // Get a random number between 0 and 5 unsigned int randomRoll = rand() % 6;

  • Please write below code in C++ using Visual Studio. Write program that uses a class template...

    Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...

  • 12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try...

    12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT