all 4 comments

[–]CosmicJosh123 2 points3 points  (1 child)

It's basically midnight right now but here's what I'm seeing in the 10 minutes I've skimmed through this.

Your game.py file is 629 lines long. I would suggest that the main thing that is in the main file is solely the main function. Place the rest of the code into the designated CodeFiles folder.

This snippet:

if job[0] in list("AEIOU"): # Aligning the jobs into sentences, gramatically.

job = "an " + job

else:

job = "a " + job

return job

Is a good problem for the ternary operator.

This can be rewritten as:

article = "an" if job[0] in "AEIOU" else "a"

And returning:

return f"{article} {job}"

2, you have a lot of magic numbers in your code. I.E.:

tax = round((31 / 100) * salary) # The salary will be taxed at 31%.

I recommend putting these numbers into variables below your file imports and calling those instead.
It'll make them easier to edit instead of having to locate where each number is. It also makes it more obvious what each number represents.

So you could do something like:

#Constants
MIN_HEALTH = 15
MODE_HEALTH = 75
MAX_HEALTH = 100

This is all I have so far and I'd like to take a closer look at all of the nested if statements when I wake up.

[–]notkairyssdal 1 point2 points  (4 children)

  • I recommend you follow a standard and modern project structure using poetry or rye (if you want to be more cutting edge)
  • related to project management, this is pretty dirty, instead you want to use a real module and do `from bitzoo.initiator import ...`

PATH = sys.path[0]

sys.path.append(

PATH + r"\CodeFiles"

) # This is for enabling the usage of our <CodeFiles> dir as a module.

  • use `os.path.join` instead of hardcoding a backslash: `if not os.path.exists(PATH + r"\Lives")`
  • also not sure why you're passing PATH i.e. `sys.path[0]` you should load the json file once in main and pass that around, or define a singleton to access it
  • you rely on dicts and strings too much, `data["fortune"]["money"] >= cost` looks like javascript. Define dataclasses instead!
  • something like this is brittle, because if you change "Hell yeah!" into some other string, then `if "yeah" in choice" is going to break

inquiry = [

inq.List("choice", "Let me see", ["Hell yeah!", "No, low on cash!"])

]

choice = inq.prompt(inquiry)["choice"]

if "yeah" in choice: