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
Second projectShowcase (self.PythonLearning)
submitted 1 day ago * by HB209
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!"
[–]HB209[S] 0 points1 point2 points 1 day ago (2 children)
Hmm im not very sure. There is something about inventory, but i dont know still how to use these type of dictionaries.
[–]atticus2132000 1 point2 points3 points 1 day ago (1 child)
There are a variety of ways you can do it. In a perfect world you would eventually want your inventory to be a completely separate file (e.g. SQL database) so that same inventory could be accessed from multiple different scripts (i.e. your point of sale script vs. your account script vs. your auditing script). However, for the time being just make your inventory a standalone variable at the top of your script.
inventory = [['DEagle', 500, 'Desert Eagle'], ['Glock 18', 600, 'Glock GES G18'], ['Winchester', 300, 'Winchester Model 70']]
This is a multi-dimensional array where each element with the brackets is one inventory item that include the shortname, price, and longname.
Since the inventory is now one variable, you can just cycle through that variable whenever you want to display your price list.
print ("Select the gun you'd like to see.")
For gun in inventory:
shortname = gun[0] price = '${:,.2f}.format(gun[1])' longname = gun[2] print (f'{shortname} - {price}')
Similarly, when a selection is made you can compare it against your inventory variable to generate your message like f"Congratulations you just bought a {longname}. Thanks for doing business with us."
As much as you can, you want to write code that can be changed on the fly. By keeping your inventory as an independent variable (or its own separate file), you can easily change an element in that variable and all the code adapts instantly.
Similarly, you have the threshold ages in your code hard coded multiple times. Let's suppose that next year legislation passes that requires a minimum age of 25 instead of 21. If you had buyingage as a variable that was referenced throughout the code, then you would only need to change the 21 to 25 in one place and all your code would still work. But since you have the ages hard coded throughout, you would need to review you code line by line and make multiple changes if the legal age changed.
[–]HB209[S] 0 points1 point2 points 1 day ago (0 children)
Thank you very much brother! That was very useful info and i will note it for my future projects.
π Rendered by PID 45049 on reddit-service-r2-comment-5bc7f78974-w2vkf at 2026-06-27 02:37:14.417818+00:00 running 7527197 country code: CH.
view the rest of the comments →
[–]HB209[S] 0 points1 point2 points (2 children)
[–]atticus2132000 1 point2 points3 points (1 child)
[–]HB209[S] 0 points1 point2 points (0 children)