« All Events
6 PM – Python OOP – Shawn
October 3, 2023 @ 6:00 pm - 7:00 pm
Today We Did
- We reviewed the homework from page 105.
- We started converting Aug8_GrocerrySystem.py into oct_3_grocerry_shopping_cart_dictionary.py.
Homework
- Create oct_3_robux_shopping_cart_dictionary.py
- Copy codes from Robux Shopping Cart project (click here) into this new python file.
- 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.
- Change the code so the item name and the prices are no longer hard coded but pulled from the 2 dictionaries.
- Inside oct_3_grocery_shopping_cart_dictionary.py 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
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)