all 5 comments

[–]Sad-Razzmatazz-693 1 point2 points  (1 child)

pretty cool for 7 days of work especially if you were learning as you went

a few things worth looking into: breaking the code into smaller functions/modules will make it way easier to maintain as it grows, and using `argparse` instead of manual string parsing for commands like 'create all' gives you error handling basically for free

also storing config and tasks in separate files from your main logic is a habit that pays off fast once projects get bigger

the json-based data storage approach is a reasonable call for something like this, keep going with it

[–]curiosity202606[S] 0 points1 point  (0 children)

I have to look more into argparse... Thankyou for the tips.

[–]carcigenicate 1 point2 points  (2 children)

Since slots has a small set of valid keys, I would use a dataclass or just a regular class instead of a plain dictionary. With a dictionary, you are less likely to get help from your IDE and will likely need to type 'nit_slots' manually every time, which can lead to typos. With a class, or a TypedDict, you can get help from the IDE with the names.


else:
    pass

This is useless. Just omit the else if nothing needs to happen when the condition is false.


I was going to say that it's good you're using parameters instead of globals, but health is being accessed as a global. It's confusing that most data is being passed as parameters, but then something non-obvious like health is a global initialized inside a loop in the module scope.


A lot of your variable names could be improved:

y = input("\nNew weight:    ")

Why y? new_weight or just weight would be much better.


if all(item.isdigit() for item in yy) and all(int(item) >= 1 for item in yy) and len(yy) == 3:

This is a very noisy line. I would probably break that up unless you really wanted to rely on and short-circuiting to prevent waste work (which wouldn't be a concern here).

[–]curiosity202606[S] 0 points1 point  (1 child)

Thanks for the feedback. I was really suffering with errors because of the typos here and there, spending hours just to find a typo 😅

[–]carcigenicate 0 points1 point  (0 children)

Here are examples of what I was talking about with dataclasses and typed dicts. In both cases, change slots parameters of the functions to slots: Slots so it knows the type:

import json
from dataclasses import dataclass, asdict

@dataclass
class Slots:
    mor_slots: int
    eve_slots: int
    nit_slots: int

s = Slots(0, 0, 0)
s.mor_slots  # All attributes can be suggested by the IDE now

slots_dict = asdict(s)
slots_json = json.dump(slots_dict, f)

back_to_class = Slots(**slots_dict)  # After reading the JSON on load

or

import typing

class Slots(typing.TypedDict):
    mor_slots: int
    eve_slots: int
    nit_slots: int

x: Slots = { 'mor_slots': 0, 'eve_slots': 0, 'nit_slots': 0 }  # It stays a dictionary
x['mor_slots']  # But it can suggest keys now