American Young Coder Academy – Indo

Loading Events

« All Events

  • This event has passed.

5:00 PM – Python Object Oriented Programming – Sebastian

June 13, 2023 @ 5:00 pm - 6:00 pm

Today We Did
  1. Reviewed homework
  2. Spent a lot of time understanding the pro’s and con’s of attributes vs using the variables we learned about in the beginning of class “local variables”
  3. Reviewed the core concepts of object oriented programming before moving on to inheritance (coming up next week)
  4. In case you need anything, feel free to email me at sebastian@ayclogic.com
Homework
  1. Name your homework JUN13_supermarket_hw, please submit by next Monday.
  2. Homework: Given the code that we have, finish up the rest of the ShoppingCartApplication class by adding the correct print statements where the comments specify.

    from groceryitem import GroceryItem
    
    
    class ShoppingCartApplication:
    
        def __init__(self):
            self.menu = """
    What do you want to purchase:
    1. Milk - $5
    2. Eggs - $4
    3. Orange Juice - $6
    4. I am done, checkout please
    Enter your selection: """
            # List of GroceryItem
            self.shopping_cart = []
            # Dictionary mapping selection to GroceryItem
            self.menu_items = {
                "1": GroceryItem("Milk", 5, True),
                "2": GroceryItem("Eggs", 4, True),
                "3": GroceryItem("Orange Juice", 6, False)
            }
    
        def check_out(self):
            cost = 0
            for grocery_obj in self.shopping_cart:
                if grocery_obj.is_frozen:
                    pass  # Should print "Frozen grocery item: Milk"
                else:
                    pass  # Should print "Normal grocery item: Orange Juice"
                cost += grocery_obj.price
            print("total cost:", cost)
    
        def application_loop(self):
            while True:
                selection = input(self.menu)
                if selection not in ["1", "2", "3", "4"]:
                    print("Invalid selection")
                elif selection == "4":
                    break
                else:
                    grocery_obj = self.menu_items[selection]
                    self.shopping_cart.append(grocery_obj)
            self.check_out()
    
    
    cart = ShoppingCartApplication()
    cart.application_loop()

Details

Date:
June 13, 2023
Time:
5:00 pm - 6:00 pm
Event Category:
Verified by MonsterInsights