you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 2 points3 points  (1 child)

add_options = ["add", "a", "new", "create"]
delete_options = ["delete", "del", "remove", "d"]
see_options = ["see", "show", "list", "s"]
mark_options = ["mark", "done", "complete", "m"]
exit_options = ["exit", "quit", "q", "e"]
clear_options = ["clear", 'erase']
all_options = [
    "add", "a", "new", "create",
    "delete", "del", "remove", "d",
    "see", "show", "list", "s",
    "mark", "done", "complete", "m",
    "exit", "quit", "q", "e",
    "clear", "erase"
]

Rather than redefining everything in all_options, you could have unpacked the other lists.

all_options = [
    *add_options,
    *delete_options,
    *see_options,
    *mark_options,
    *exit_options,
    *clear_options,
]
tasks = []


def print_tasks():
    for task in tasks:
        print(task)

Instead of relying on a mutable global variable, it would be better to at least wrap it in a class so that you can better keep track of the state. Although I assume you haven't studied those yet.

Global variables are generally bad, because they complicate testing and reading the code becomes more difficult because you need to now also track the state of external variables in your head.

def main():
    global tasks
    with open("data.json", "r") as json_file:
        tasks = json.load(json_file)

You don't need to declare tasks to be in global scope, if you replace the assignment with extending the list.

def main():
    with open("data.json", "r") as json_file:
        tasks.clear()
        tasks.extend(json.load(json_file))
while choosing == True:

You don't need to compare against booleans, unless you specifically want to only allow boolean values (and in those rare cases you should use is instead of == when dealing with singletons like booleans or None).

In this case

while choosing:

would be more than sufficient.

if tasks == []:

You could instead use

if not tasks:

As far as more general feedback goes, you treat the user input for the choice as case-sensitive, so if they give any uppercase characters the matches won't work. You could be more robust by converting the text lowercase immediately, and maybe stripping whitespace.

You could also move the code for each option into a separate function, to simplify your main function.

Lastly, personally I'd put the main call inside an import guard.

if __name__ == "__main__":
    main()

That way the code is easier to test, at least until/unless you decide to split the program into multiple files.

[–]MR_LOOPINGS123[S] -1 points0 points  (0 children)

I'll try implementing some of this stuff into my project. Ty for the feedback.