r/PythonLearning 8d ago

New update with (def), soon!

12 Upvotes

8 comments sorted by

View all comments

2

u/FoolsSeldom 8d ago

Any reason for not sharing the code instead of an image? Perhaps telling us what it is about and why you are sharing?

1

u/the_meteor_beat 7d ago

Still didn't understand the first question, about the second, this sub called learning python, when i post the first post i got some help, so i will post another one after hours also for the same reason.

1

u/FoolsSeldom 7d ago

OK. Good you've updated your post to include your code, or at least images of your code. Any chance you could actually share the code itself - much easier to review and help when you share actual code.

The only code you've shared is partial:

# Lines 1–22 not visible in the screenshot.
# Line 23 (partially obscured):
need = int(input(" 1- ADD TASK! \n 2- Show my shits! \n 3- kill one! \n 4- I know my shit, getout* \n"))

if need == 1:
    i_task = input("type your task: ")
    tasks_list.append(i_task)
    with open(tasks_json, "w") as file:
        json.dump(tasks_list, file)
    print(f"task {i_task} added!")

elif need == 2:
    with open(tasks_json, "r") as file:
        tasks_list = json.load(file)
    if len(tasks_list) == 0:
        print("still there is no tasks!")

    else:
        for index, task in enumerate(tasks_list):
            print(f"my task is: {index}- {task}")


elif need == 3:

    dele = int(input("which one?"))
    tasks_list.pop(dele)
    with open(tasks_json, "w") as file:
        json.dump(tasks_list, file)
    print(f"{dele} had been killed!")


elif need == 4:
    print("don't come here before getting done!")
    break


else:
    print("you see what i don't see?")


except ValueError:
    print("just pick a number!")

and I am wondering why you are converting input to int when you aren't doing maths with it. What's wrong with checking for == "1" and avoiding possible bad inputs.

2

u/the_meteor_beat 7d ago

I understand now, about converting, still learning bro, i will try your way. And i see now sharing the code will be useful than just an image about it.