100 days of code: Day 26 - classes

Last modified on 2020-07-04

Source: 100-days-of-code.

My first small bit of object-oriented programming, writing a class to create objects

class Restaurant:
    """A simple attempt to model a restaurant."""

    def __init__(self, restaurant_name, cuisine_type):
        """Initialize restaurant name and type of cuisine."""
        self.name = restaurant_name
        self.cuisine = cuisine_type

    def describe_restaurant(self):
        """A restaurant's name and type of cuisine."""
        print(f"{self.name} is known for their {self.cuisine}.")

    def open_restaurant(self):
        """Indicate that the restaurant is open for business."""
        print(f"{self.name} is open for business.")

diner = Restaurant('Zets', 'souvlaki')
italian = Restaurant('Luigi', 'fettucini')
vegetarian = Restaurant('New Leaf', 'black bean burgers')


Run …

$ python3 restaurant.py 
Zets is known for their souvlaki.
Zets is open for business.
Luigi is known for their fettucini.
New Leaf is known for their black bean burgers.
New Leaf is open for business.

Happy hacking!