RESOURCES:
Class slides: https://docs.google.com/presentation/d/1kmWz86R6X1BuYi3Z952yiPgmlvWuow9KU0RXoCkKK8w/edit?usp=sharing
Example code: https://replit.com/@ShravyaS/IntroToPython-16
(This contains the solution to the mini-project and more information about tuples, so if you need help with dictionaries, just email me at shravyassathish@gmail.com :))
HOMEWORK / MINI-PROJECT:
Write a program that can accept menu items and menu prices, until the word "done" is entered. Store each item and price in a dictionary. Then, print out everything together as a fancy menu.
ex:
duck
35
chopsticks
10
done
duck . . . . . . $35
chopsticks . . . . . . $10
Write your answer as a comment, and feel free to email the TAs (Shravya and Eric) if you're stuck. See you next class!
import random menu_dict = {}; print("Please input your menu items and price, type 'done' to finish"); dict_key = ""; while(1): print('what is your menu item?'); dict_key = input(); if(dict_key == "done"): print("Menu item completed"); break; print("What is your item price?"); dict_value = input(); if(dict_value == "done"): print("Menu item completed"); break; menu_dict[dict_key] = dict_value; print("Here's your fancy menu\n") for key in menu_dict: print(f"{key} ....... ${menu_dict[key]}")
Solution
list = {} x=0 y=0 while x!="stop" and y!="stop": x=input() if x != "stop": y=input() if y != "stop": i=["$",y] list[x] = "".join(i) for i in list: print(i, "......", list[i])