From 6e75f60cd3f7f95ce68c24763c564e98cdd48f93 Mon Sep 17 00:00:00 2001 From: cheeks <134818917+leftovertoast@users.noreply.github.com> Date: Sat, 1 Mar 2025 16:19:55 +0000 Subject: [PATCH] Completed 9-6 Ice Cream Stand --- Chapter_09/9-06_ice_cream_stand.py | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Chapter_09/9-06_ice_cream_stand.py diff --git a/Chapter_09/9-06_ice_cream_stand.py b/Chapter_09/9-06_ice_cream_stand.py new file mode 100644 index 0000000..4fa9757 --- /dev/null +++ b/Chapter_09/9-06_ice_cream_stand.py @@ -0,0 +1,47 @@ +# Exercise 9-6 Ice Cream Stand +# Learning Objective: Create a class that inherits the Restaurant class. Add an attribute and create a method. Create instance to make sure it works properly. + +class Restaurant: + def __init__(self, name, cuisine_type): + """Initialize variables name and cuisine_type, define functions to describe and to open restaurant...""" + + self.name = name + self.cuisine_type = cuisine_type + self.number_served = 0 + + def describe_restaurant(self): + """Describe the restaurant""" + print(f"The restaurant's name is {self.name} and the cuisine served here is {self.cuisine_type}") + + def open_restaurant(self): + """Simulate it being opened""" + print(f"{self.name} is now open for business.") + + def get_number_served(self): + """Retrieve current number of customers that have been served.""" + print(f'{self.number_served} customers have been served at {self.name} so far.') + + def set_number_served(self, num): + """ Enable manual modification to number of customers served""" + self.number_served = num + + def increment_number_served(self): + """Incremental change to number of customers served""" + self.number_served += 1 + +class IceCreamStand(Restaurant): + def __init__(self, name, cuisine_type): + """Initialize parent class attributes, then add attributes specific to Ice Crean Stand""" + super().__init__(name, cuisine_type) + self.flavors = [] + + def print_flavors(self): + """Prints out the list of flavors provided""" + print(f"The flavors available here are {self.flavors}.") + + +carphel = IceCreamStand("carphel", "ice cream") + +carphel.flavors = ['chocolate, vanilla, strawberry, mocha, peach'] + +carphel.print_flavors() \ No newline at end of file