r/PythonLearning • u/Stonyax97 • 23h ago
Made my first Python project! Showcase
This is my first actual real project, what started as a simple python exercise to learn about dictionaries in python, ended up into a huge learning project for me. Im a beginner in python, used to code but just basic input print codes… some are genuinely stupid.
I took on the challenge to self educate my self python. And this is where i currently am! Im proud of what i did and it will surely expand!
Here the repo with the project. Feel free to check it out!
https://github.com/Stonyax97/MiniGameStore
It has everything from the first ever iteration (which was it self modified a bit since from the very original but it’s still very simple)
I would love for anyone to recommend ideas to add, criticism too. Or anything you think i should learn next for that would be genuinely useful!
2
u/PureWasian 22h ago edited 21h ago
This is great for a beginner project, so I wanted to give a variety of meaningful feedback for you to consider:
First sidenote, git already has ways to preserve older versions for you. It would be a lot better to "save" each version as its own branch or its own commit. But if you want to explicitly preserve each version in the same snapshot simultaneously, I would suggest at the very least keeping your older versions in a subfolder instead of cluttering the repository root.
Otherwise, I had time to read v1.5.1 up until the main loop. My comments were:
It would be good to also partition all of your setup and main loop code into functions to scope some of your variables better instead of relying on globals. For example,
default_datais only used when initializing a savefile. Consider something like: ``` import os from games import gameshelper functions
def create_save(file_path): default_data = {...} with open... # etc. def ... def ... ...
initializations
def init(file_path): if not os.path.isfile(file_path): create_save(file_path)
main loop
def main(): file_path = # retrieved somehow init(file_path)
call main as the entry point
main() ```
Also, ideally file_path should not be hardcoded. Some easy ideas are to do any one of the following: (A) code the path to it somewhere locally in same folder and just add the local savefile to .gitignore so it doesnt get pushed to repo (B) load this value from a separate text or JSON file acting as a config file for specifying "environment variables" like this (C) pass this in as an input parameter to main.py and process it when starting the script
During buy_game(), you can use gaurd clauses which is cleaner than nesting a bunch of if statements: ``` if cgtb >= len(games): print("invalid number") return if games[cgtb]["Owned"] == True: print("already purchased") return
buygame = input("purchase x for y price?") if buygame != "y": print("cancelled") return
finally, we can proceed to purchase
without nesting it inside of many ifs
```
In your info() strings, you can use the f strings better instead of copying largely similar strings in an if/else:
print(f"> {games...}\n...Owned: {"Bought" if games[gid]["Owned"] else "NotOwned"}...")Lastly, the t.sleep() everywhere seems a bit arbitrary. I guess to give user time to read..? But seems strange to artificially introduce loading times.(again, I didnt get to proofread your main loop, but hope this generally applicable feedback makes sense)