nord vpnnord vpn
Ad

Hansen's Car Retail Shop

mail@pastecode.io avatar
unknown
python
a year ago
3.5 kB
9
Indexable
Never
class cars():
    def __init__(self, name, brand, capacity, country): # Must put __init__ cuz it's a constructor
        self.name = name
        self.brand = brand
        self.capacity = capacity
        self.country = country

    def get_name(self):
        return self.name

    def get_brand(self):
        return self.brand

    def get_capacity(self):
        return self.capacity

    def get_country(self):
        return self.country

    def set_name(self, name):
        self.name = name

    def set_brand(self, brand):
        self.brand = brand

    def set_capacity(self, capacity):
        self.capacity = capacity

    def set_country(self, country):
        self.country = country


def reset_data(): # Don't need repeat the same code
    global car1
    global car2
    global car3
    car1 = cars("Model 3", "Tesla", "1000kg", "US")
    car2 = cars("Z4", "BMW", "1610kg", "Germany")
    car3 = cars("Serena e-POWER", "NISSAN", "1740kg", "Japan")


reset_data()

tick = 0

while tick == 0:
    print("{~~~~~[Cars at the Hansen's Car Retail Shop]~~~~~}")
    print("1:", car1.brand, car1.name)
    print("2:", car2.brand, car2.name)
    print("3:", car3.brand, car3.name)
    print("{~~~~~~~~~~~~~~~~~~~~~~~~~}")

    user_selected_car = int(
        input("Which car would you like to choose? (answer in numbers): "))

    print("{~~~~~~~~~~[Info]~~~~~~~~~~}")
    print("1. name")
    print("2. brand")
    print("3. capacity")
    print("4. country")
    print("5. full info")
    print("{~~~~~~~~~~~~~~~~~~~~~~~~~}")

    info = int(input("Which info would you like to check? (answer in numbers): "))

    # Set car class to a variable
    if user_selected_car == 1:
        car_class = car1
    elif user_selected_car == 2:
        car_class = car2
    elif user_selected_car == 3:
        car_class = car3

    # Don't need 'if else' for each car ;)
    if info == 1:
        print(car_class.get_name())
        ques = input("Would you like to change info? Y/N: ")
        if ques.lower() == "y":
            ans = input("Please insert changed stat: ")
            car_class.set_name(ans)
    elif info == 2:
        print(car_class.get_brand())
        ques = input("Would you like to change info? Y/N: ")
        if ques.lower() == "y":
            ans = input("Please insert changed info: ")
            car_class.set_brand(ans)
    elif info == 3:
        print(car_class.get_capacity())
        ques = input("Would you like to change info? Y/N: ")
        if ques.lower() == "y":
            ans = input("Please insert changed info: ")
            car_class.set_capacity(ans)
    elif info == 4:
        print(car_class.get_country())
        ques = input("Would you like to change info? Y/N: ")
        if ques.lower() == "y":
            ans = input("Please insert changed info: ")
            car_class.set_country(ans)
    elif info == 5:
        print(car_class.get_brand(), car_class.get_name(),
              car_class.get_capacity(), car_class.get_country())

    print("{~~~~~~~~~~~~~~~~~~~~~~~~~}")
    print("Would you like to,")
    print("1. Reset info?")
    print("2. Quit programme?")
    print("3. Continue?")
    
    ans = int(input())
    if ans == 1:
        reset_data()
    elif ans == 2:
        print("Thank you for visiting. Hope to see you again! ")
        print("{~~~~~~~~~~~~~~~~~~~~~~~~~}")
        tick = 1
    else:
        pass

nord vpnnord vpn
Ad