Today we did:
- We reviewed the homework and finished GroceryShoppingCartV2.
Homework:
- In your March25_RobuxShoppingCartV2.py, make sure to change this file in the same way we did for the GroceryShoppingCartV2. Make the two dictionaries that map to the item and map to the price, then take from those dictionaries based on the selection and that will be the item name and price for that item selection. Only difference is that you will need to subtract the item’s price from the total amount of Robux you have. But you need to check if you have enough Robux to do so (hint: compare the robux vs the item price to see which one is greater), and if you have enough, then proceed with the item purchase (basically you bought the item and your total Robux balance is decreased). If you don’t have enough, then you should print something like <Not enough robux>.
- As exercises for practicing your dictionary skills,
- Create a new file called March25_DictionaryHomework.
- Make a dictionary called sports and fill it in with 6-7 items. Each item contains the key, which is the name of a person, and the value, which is the sport name.
- Add 2 more items to the dictionary.
- Delete one of the items of your choice from the dictionary.
- Ask the user for a person’s name. Check if the name of the person is in the dictionary (figure out if we have to check using .keys() or .values()). If it is, print the name of the person and the sport ({name} – {sport} is fine). Remember the crucial step, which is to take the sport (value) using the name found (key) in order print the sport value. Finally, if the person’s name is not in the dictionary, then print <We could not find this person in the dictionary>.
- Print all the names in the dictionary using a for loop.
- Print all the sports in the dictionary using a for loop.
- Print the names and sports at the same time using a for loop.
I know this is more than usual, but trust me, it’s good practice. Make sure to do your best!
If you have any questions, feel free to email me at joel@ayclogic.com.