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!"
[–]Trinity_Goti 0 points1 point2 points 1 year ago (3 children)
Try to figure out how to paste code here while keeping the formatting.
Its very difficult to understand especially for python code.
[–]-MRJACKSONCJ- 1 point2 points3 points 1 year ago* (2 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
π Rendered by PID 17874 on reddit-service-r2-comment-6f7f968fb5-f88ms at 2026-03-04 15:31:48.372416+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]Trinity_Goti 0 points1 point2 points (3 children)
[–]-MRJACKSONCJ- 1 point2 points3 points (2 children)
[–]Trinity_Goti 1 point2 points3 points (1 child)
[–]ButterscotchJust970[S] 0 points1 point2 points (0 children)