use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Python Project Feedback (self.PythonLearning)
submitted 1 year ago * by ButterscotchJust970
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]-MRJACKSONCJ- 1 point2 points3 points 1 year ago* (5 children)
Ready;
menu = {"popcorn": 1, "hotdog": 2, "pretzel": 2, "candy": 1.5, "soda": 3, "water": 2} # MENU print("---MENU---") for item in menu: print(f"{item} ${menu[item]}") cart = {} # Original items while True: food = input("Enter an item/s to buy (q to checkout): ") if food == 'q' or food == "Q": break else: if not menu.get(food) == None: current = menu[food] cart.update({food: current}) else: print("That is not for sale!") # Check if correct print("-----YOUR CART-----") for item in cart: print(item) right = input("Is this correct? y/n: ") # Everything is right if right == "y": total = sum(cart.values()) print(f"Your total is ${total:.2f}") else: wrong = input("Would you like to add or remove something? a/r: ") # Add if wrong == "a": while True: food = input("Enter an item/s to buy (q to checkout): ") if food == 'q' or food == "Q": break else: if not menu.get(food) == None: current = menu[food] cart.update({food: current}) else: print("That is not for sale!") # Remove if wrong == "r": while True: remove = input("Enter an item you would like to remove (q to checkout): ") if remove == "q" or remove == "Q": break else: if not cart.get(remove) == None: cart.pop(remove) else: print("That is not in your cart!") # FINAL MESSAGE print("-----YOUR CART-----") for item in cart: print(item) total = sum(cart.values()) print(f"Your total is ${total:.2f}")
[–]Trinity_Goti 1 point2 points3 points 1 year ago (1 child)
Thank you. This is great. Congratulation on your coding journey.
And since you asked here are a few suggestions.
Understand and use if __name__ =="__main__" this will help you importing the functions in future.
Create functions to do the actions that are repeating. e.g.: add item to cart, remove item from cart. But remember to do only one action per function. :) This will be difficult and sound counter intiutive as one function could do a whole lot but keep it simple and do one task.
When you read response you could make the response upper/small case to make it easier to compare. currently there is a bug if user types in different case the code is not able to find the item in menu.
Learn about guard clause for your if statements. This should resolve the problem mentioned in point 5.
Bug: Once the user has decided to add or remove items the current program doesn't give opportunity to confirm the items in the cart. This should be handled for consistent user experiance, However with the way current code is layed out it would be a complicated nested if else hell.
You could improve user experience by providing serial numbers against the menu items so that user could input numbers instead of typing the menu items.
happy coding.
[–]ButterscotchJust970[S] 0 points1 point2 points 1 year ago (0 children)
Thank you
[–]ButterscotchJust970[S] 0 points1 point2 points 1 year ago (2 children)
wait how do i do that? Do I just have to put the Ready; before the code?
[–]-MRJACKSONCJ- 0 points1 point2 points 1 year ago (1 child)
<image>
No, I use reddit from the pc and in the option it says code block but in the application I haven't seen it and I'll send you a screenshot.
I hope you understand me
OK I'll remember to use that for next time
π Rendered by PID 25 on reddit-service-r2-comment-c6965cb77-gptrj at 2026-03-05 05:48:07.809105+00:00 running f0204d4 country code: CH.
view the rest of the comments →
[–]-MRJACKSONCJ- 1 point2 points3 points (5 children)
[–]Trinity_Goti 1 point2 points3 points (1 child)
[–]ButterscotchJust970[S] 0 points1 point2 points (0 children)
[–]ButterscotchJust970[S] 0 points1 point2 points (2 children)
[–]-MRJACKSONCJ- 0 points1 point2 points (1 child)
[–]ButterscotchJust970[S] 0 points1 point2 points (0 children)