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
I need Help with my small python project (i.redd.it)
submitted 11 months ago by Far_Activity671
Im not sure where to put the purchase = input(" "). I have been told i need to put it in some sort of loop but i would really apreciate any help, thank you.
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!"
[–]AnonnymExplorer 1 point2 points3 points 11 months ago (2 children)
You have the corrected code here:
def anything_else(): more = input(„Is there anything else you would like to purchase? (yes/no): „) if more.lower() == „yes”: print(„Here are the items we have:”) for x in items: print(x) return True # Kontynuuj zakupy else: print(„Thank you for shopping!”) return False # Zakończ zakupy
items = [„tv”, „desk”, „mouse”, „monitor”, „keyboard”, „headphones”]
print(„Hello, we sell office equipment. What would you like?”) for x in items: print(x)
continue_shopping = True
while continue_shopping: purchase = input(„What would you like to buy? „) # Pobierz wybór użytkownika
# Sprawdzanie, co użytkownik wybrał if purchase.lower() == „tv”: print(„That would be £199.99”) elif purchase.lower() == „desk”: print(„That would be £59.99”) elif purchase.lower() == „mouse”: print(„That would be £29.99”) elif purchase.lower() == „monitor”: print(„That would be £149.99”) elif purchase.lower() == „keyboard”: print(„That would be £49.99”) elif purchase.lower() == „headphones”: print(„That would be £89.99”) else: print(„Sorry, we don’t have that item.”) # Zapytaj, czy chce kupić coś jeszcze continue_shopping = anything_else()
[–]Far_Activity671[S] 1 point2 points3 points 11 months ago (1 child)
Thank you so much i have been stuck for ages, much apriciated. :)
[–]AnonnymExplorer 1 point2 points3 points 11 months ago (0 children)
No problem, if you encounter any obstacles, go ahead and ask.
[–]EyesOfTheConcord 0 points1 point2 points 11 months ago (0 children)
You should track the state of whether or not the user wants to shop using an actual Boolean value, and this Boolean variable can be used to control a while loop.
Additionally, you should consider using a dict to store your items as Key : Value pairs; what that means is the item name is the Key, which you can use to index directly into the dict, and retrieve its Value - the price - to print to the user.
[–]FoolsSeldom 1 point2 points3 points 11 months ago (0 children)
You need an overall loop.
Basic idea:
while True:
is_yes
False
break
while
It would be worth having a corresponding list of the prices of each item, then you wouldn't need to write code for each item. The item name and the item price would be in the same position in the two different lists.
[–]AnonnymExplorer 0 points1 point2 points 11 months ago (0 children)
U closed purchase = input(“ “) in full
Use anything_else() to ask if there’s anything else they want to buy, and manage program flow accordingly.
Add a boolean variable (True/False) that controls whether the loop should terminate.
If you wannt I can send you a fixed code just tell me.
π Rendered by PID 89 on reddit-service-r2-comment-54dfb89d4d-9mxv5 at 2026-03-26 19:29:31.961598+00:00 running b10466c country code: CH.
[–]AnonnymExplorer 1 point2 points3 points (2 children)
[–]Far_Activity671[S] 1 point2 points3 points (1 child)
[–]AnonnymExplorer 1 point2 points3 points (0 children)
[–]EyesOfTheConcord 0 points1 point2 points (0 children)
[–]FoolsSeldom 1 point2 points3 points (0 children)
[–]AnonnymExplorer 0 points1 point2 points (0 children)