American Young Coder (AYC)

Loading Events

« All Events

  • This event has passed.

6 PM – Python OOP – Shawn

October 3, 2023 @ 6:00 pm - 7:00 pm

Today We Did
  1. We reviewed the homework from page 105.
  2. We started converting into
  1. Create
    1. Copy codes from Robux Shopping Cart project (click here) into this new python file.
    2. Similar to what we did in the class, add two new dictionaries: item_name to store the item names, item_prices to store the item prices.
    3. Change the code so the item name and the prices are no longer hard coded but pulled from the 2 dictionaries.
  2. Inside file that we did in the class, change the code according to below instruction. Below four “if” and “elif” statements can be simplified into one if statement. Please think how we can do this and change the code accordingly. Hint: “selection” variable is the “key” for for “item_prices” and “item_names” dictionaries
    1. while True:
          selection = input(menu)
          if selection == "1":
              item = item_names["1"]
              price = item_prices["1"]
              transaction(item, price)
          elif selection == "2":
              item = item_names["2"]
              price = item_prices["2"]
              transaction(item, price)
          elif selection == "3":
              item = item_names["3"]
              price = item_prices["3"]
              transaction(item, price)
          elif selection == "4":
              item = item_names["4"]
              price = item_prices["4"]
              transaction(item, price)


October 3, 2023
6:00 pm - 7:00 pm
Verified by MonsterInsights