I am trying to make it so when an instance of Customers is created and the restaurant they are going to is specified the number_served instance attribute of that instance of the Restaurant class is incremented by the number of customers going to the restaurant.
I am not sure if the number_served should be a class or instance attribute (i think class) and I am not sure how I can inherit the attribute from the Restaurant class to the Customers class so I can increment it.
class Restaurant:
def __init__(self,name,restaurant_type,cuisine_type):
self.name = name
self.restaurant_type = restaurant_type
self.cuisine_type = cuisine_type
self.number_served = 0
def describe_restaurant(self):
print(f"{self.name} is {self.restaurant_type} which serves {self.cuisine_type}.")
def open_restaurant(self):
print(f"{self.name} is open.")
def get_number_served(self):
print(f"{self.number_served} customers served at the {self.name} today.")
def increment_number_served(self,num):
self.number_served += num
class Customers(Restaurant):
def __init__(self,where_eating,no_of_people):
self.where_eating = where_eating
self.no_of_people = no_of_people
def go_eat(self):
self.increment_number_served(self.no_of_people)
I basically want the number_served attribute of a restaurant instance to be incremented by the number of customers who went to the restaurant from an instance of the Customers class
Customersinheriting fromRestaurantin the first place? A customer is not a kind of restaurant.Customers.go_eatshould take aRestaurantinstance as an argument, and theincrement_number_servedmethod of that instance should be invoked.__init__constructor. You need to usesuper().__init__(...)to correctly initialize instances