Completed 9-6 Ice Cream Stand
This commit is contained in:
parent
47e2cc027c
commit
6e75f60cd3
47
Chapter_09/9-06_ice_cream_stand.py
Normal file
47
Chapter_09/9-06_ice_cream_stand.py
Normal file
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user