Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

Can someone please help me how to locate the class name, object attribute and variables, and object methods from the code below...
I'm so confused, please help! thank you
import sys
import numpy as np


frankston_stock = []
sunbury_stock = []
werribee_stock = []


def main():
all_vehicles = read_from_file()

frankston_stock.extend(all_vehicles[0])
sunbury_stock.extend(all_vehicles[1])
werribee_stock.extend(all_vehicles[2])

view_menu()

def view_menu():
""""""
menu = "\n"+43*"-"
menu += "\nToyota Car Stock Software \n"
menu +="\n"+43*"-"
menu += "\na. Add a vehicle\n"
menu += "b. Display dealers stock\n"
menu += "c. Remove a vehicle\n"
menu += "d. Save to file\n"
menu += "e. Exit\n"
menu += "Choose Your Choice:\n"
sys.stdout.write(menu)

#
menu_choice = sys.stdin.readline().strip().lower()
if menu_choice == "a":
    add_a_vehicle()
elif menu_choice == "b":
    display_dealer_stock()
elif menu_choice == "c":
    remove_a_vehicle()
elif menu_choice == "d":
    save_to_file()

def get_all_dealer_cars():


all_dealer_cars = []

all_dealer_stock = read_from_file()

for car in all_dealer_stock:
    car.pop(0)
    all_dealer_cars.extend(car)


all_dealer_cars = np.unique(all_dealer_cars).tolist()

for car in all_dealer_cars:
    sys.stdout.write("\n".ljust(20) + car)
return


def read_from_file():

all_vehicles = []
with open("inventory.txt", "r") as dealer_car_stock:
    for line in dealer_car_stock:
        line = line.strip()
        line = line.split(",")
        if line[0] == "Frankston" or line[0] == "Sunbury" or line[0] == "Werribee":
            all_vehicles.append(line)

        else:
            sys.stdout.write("File is empty or corrupted")

return all_vehicles


def display_dealer_stock():



frankston_cars = []
sunbury_cars = []
werribee_cars = []

toyota_location = ["All Dealers", "Werribee", "Sunbury", "Frankston\n"]

for i in range(0, len(toyota_location)):

    
    sys.stdout.write("\n"+30*"="+"\n")
    sys.stdout.write("\nToyota Dealership".ljust(20) + toyota_location[i])
    sys.stdout.write("\nCurrently In Stock")
    
    if toyota_location[i] == "Frankston":

        frankston_cars.extend(frankston_stock)

        frankston_cars.pop(0)

        print_vehicles(np.unique(frankston_cars).tolist())
    elif toyota_location[i] == "Sunbury":
        sunbury_cars.extend(sunbury_stock)

        sunbury_cars.pop(0)

        print_vehicles(np.unique(sunbury_stock).tolist())
    elif toyota_location[i] == "Werribee":
        werribee_cars.extend(werribee_stock)

        werribee_cars.pop(0)

        print_vehicles(np.unique(werribee_cars).tolist())
    else:
        get_all_dealer_cars()

view_menu()


def add_a_vehicle():
""""""
sys.stdout.write("Please select following dealer locations: \n1.Frankston \n2.Sunbury\n3.Werribee\n")

while dealer_location != "":
    if dealer_location == "1":
        sys.stdout.write("Please enter vehicle to be added to Frankston stock: \n")
        add_vehicle = sys.stdin.readline().strip()

        frankston_stock.append(add_vehicle)

        sys.stdout.write("Car has been added\n")
        view_menu()
        break
    elif dealer_location == "2":
        sys.stdout.write("Please enter vehicle to be added to Sunbury stock: \n")
        add_vehicle = sys.stdin.readline().strip()
        sunbury_stock.append(add_vehicle)
        sys.stdout.write("Car has been added\n")
        view_menu()
        break
    elif dealer_location == "3":
        sys.stdout.write("Please enter vehicle to be added to Werribee stock: \n")
        add_vehicle = sys.stdin.readline().strip()
        werribee_stock.append(add_vehicle)
        #The append() method appends car to the end of the list.
        sys.stdout.write("Car has been added\n")
        view_menu()
        break
    else:
        sys.stdout.write("Please make sure you enter the correct location: \n")
        dealer_location = sys.stdin.readline().strip().lower()



def remove(location_stock):


vehicle_model = sys.stdin.readline().strip()
while True:

    if vehicle_model not in location_stock:
        sys.stdout.write("Car not in stock\n")
        vehicle_model = sys.stdin.readline().strip()
    else:
        break
location_stock.remove(vehicle_model)
view_menu()


def remove_a_vehicle():
""""""
sys.stdout.write("Please select following dealer locations: \n1.Frankston \n2.Sunbury\n3.Werribee\n")
dealer_location = sys.stdin.readline().strip().lower()
while dealer_location != "":
    if dealer_location == "1":
        sys.stdout.write("Please enter car that you want to remove from Frankston stock list: \n")
        remove(frankston_stock)
        break
    elif dealer_location == "2":
        sys.stdout.write("Please enter carthat you want to remove from Sunbury stock list: \n")
        remove(sunbury_stock)
        break
    elif dealer_location == "3":
        sys.stdout.write("Please enter carthat you want to remove from Werribee stock list: \n")
        remove(werribee_stock)
        break
    else:
        sys.stdout.write("Wrong selection, please select again \n")
        dealer_location = sys.stdin.readline().strip().lower()



def save_to_file():

inventory_file = open("inventory.txt", "w")
num_cars = len(frankston_stock)
for i in range(0, num_cars):
    if i == num_cars - 1:
        inventory_file.write(frankston_stock[i] + "\n")
    else:
        inventory_file.write(frankston_stock[i] + ",")

num_cars = len(sunbury_stock)

for i in range(0, num_cars):
    if i == num_cars - 1:
        inventory_file.write(sunbury_stock[i] + "\n")
    else:
        inventory_file.write(sunbury_stock[i] + ",")

num_cars = len(werribee_stock)

for i in range(0, num_cars):
    if i == num_cars - 1:
        inventory_file.write(werribee_stock[i] + "\n")
    else:
        inventory_file.write(werribee_stock[i] + ",")

inventory_file.close()
sys.stdout.write("Changes has been made, thanks\n")
view_menu()


def print_vehicles(vehicle_list):
for car in vehicle_list:
    sys.stdout.write("\n".ljust(20) + car)


What I have tried:

class name, object attribute and variables, and object methods 
Posted
Updated 20-Jul-21 19:35pm

1 solution

To define a class in Python, you use the keyword class: Python Classes[^]
So all you need to do to find the class name in there is find the keyword and look to it's right.

And .. it isn't in there. So ... no classes are created in that code, and I think you need to go back to your homework question and read it again, carefully ... we can't help you with that!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900