American Young Coder

AYC logo
Loading Events

« All Events

  • This event has passed.

7:00 PM- Python OOP- Joshua

September 30, 2025 @ 7:00 pm - 8:00 pm

Today we did

  • practiced creating application loops
  • did some grocery store practice, converting an application we already know without a class to one with a class

 

Homework:
1 for our food_choices dictionary, add the remaining two foods into our dictionary

  • Key should be the number, with the value being a “grocery item”

2. In our application loop, you need to replace the passes with the code that

  1. grabs the right grocery item based on their selection
  2. adds the name to the list in our __init__
  3. adds the price to total cost

3. We have a new function shopping results

  1. print everything in our list on separate lines (for loop)
  2. print the total price
  3. Print an thank you for shopping
  4. use this function after the application loop

 

 

class GroceryItem:
    def __init__(self,name,price,type):
        self.name = name
        self.price = price
        self.type = type
# remember to give me a thumbs up when you have created a project
# Create a directeory called SRC
# create a file named main

# Trader Joe's application
# The options were the different foods you could buy
# you could keep track of what you bought, and the price.
# after the application loop ends (check out) we print all the food and the price

# Basics
# open up a class
# __init__ we are going to put a basic menu, and everything that we need store inbetween loops
# application loop

from groceryitem import GroceryItem

class GroceryStore1:

    def __init__(self):
        # I want you to create a menu with the following options
        # three food items
        # an exit option
        self.menu =""" 
        Welcome to Trader Joes what would you like to order 
        1. Bread - $10 
        2. Pizza - $8
        3. ChocoStrawberries - $12
        Enter your Selection(type exit to stop): 
        """

        # The goal of the application is to keep track of what you buy, and how much it is
        # think of the things we would need to store inbetween loops and put here
        self.total_cost=0
        self.shopping_cart=[]
        self.food_choices={}
        self.food_choices["1"]= GroceryItem("bread",10,"carb")


    def application_loop(self):
        # Step1 , while loop (infinite loop)
        while True:
            selection = input(self.menu)
            if selection =="1":
                # i go to the dictionary and access whats in the key "1"
                # what i just accesed is my Grocery item
                # I want you to extract the name nad price from the grocery item
                # and the name to your shopping cart and then add your price to the total cost
                pass
            elif selection =="2":
                pass
            elif selection =="3":
                pass
            elif selection =="exit":
                break
            else:
                print("invalid option try again")

    def shopping_results(self):
        pass
        # print out everything in our list
        # print out the total of price of our shopping cart
        # print a thank you message
        # call this function somewhere else
    








# create a GroceryStore1
# use the appplication_loop function with your grocerystore
trader_joes=GroceryStore1()
trader_joes.application_loop()

Details

Date:
September 30, 2025
Time:
7:00 pm - 8:00 pm