Learning OOP & Exploring Possibilities!

Today, I'm on my 16th day of 100 days of Code and Angella discussed about a whole new paradigm. OOP! Though she talks as much clearly (and slowly!!!) as possible, but DAMN SON, it was complex.


post-title

In today's section, we learned about classes and objects. Basically, classes are kind of a blueprint of something. In real life cases, it can be anything, a car, a person - anything. And an object is something which has been created from this blueprint. For an example:
Let's say a Car is a class. This class has some characteristics like it has a color (or several colors 😛) and it has number of seats. These set of characters are called attributes of a class.
Again, a Car CAN do some things, like it can move or it can stop. So, the functions that a class can perform are called methods.
In this section, we have also learned how to install packages and use Pypi to find different libraries. We have modified object attributes and called methods of a class while exercising. And finally, there was this project of creating the coffee machine again. But this time with OOP.
GOD! This literally took my whole night to finish but Alhamdu lillah, I have learned in depth & clearly about this OOP concept. Here's the code snippet for today's project -

  def print_hi(name)
  # Importing object libraries
  from menu import Menu, MenuItem
  from coffee_maker import CoffeeMaker
  from money_machine import MoneyMachine

  # Object declaration
  main_menu = Menu()
  coffee_machine = CoffeeMaker()
  process_money = MoneyMachine()

  close_machine = False
  while not close_machine:
      user_choice = input(f"What would you want? ({main_menu.get_items()}): ")
      if user_choice == "off":
          close_machine = True
      elif user_choice == "report":
          f"{coffee_machine.report()}\n{process_money.report()}"
      else:
          coffee = main_menu.find_drink(user_choice)
          if coffee is not None and coffee_machine.is_resource_sufficient(coffee):
              payment = process_money.make_payment(coffee.cost)
              if payment:
                  coffee_machine.make_coffee(coffee)

I was so overwhelmed with the size of the code that I was excited as a dog 🐶 whose owner came home after a long day 😆.
The full project can be accessed via my github repository. With this and more, I'll post tomorrow again in sha Allah with a new concept.