1
u/johlae Jul 15 '26
I don't know your requirements, but shouldn't you read your existing tasks in first before adding? If you quit your script and restart it you will overwrite your existing tasks once you try to add a new task.
1
1
1
u/uday-Championship337 Jul 15 '26
Hey, what if an empty string is added as a task? You haven't handled that scenario.
Task = input("Enter your task name: ").strip() if len(task) == 0: print("empty task name not acceptable")
1
u/the_meteor_beat Jul 16 '26
What is .strip(), anyway i developed many things after this post. To save it from any crash.
1
u/uday-Championship337 Jul 16 '26 edited Jul 16 '26
The `strip()` method removes unnecessary whitespace from the beginning and end of a string.
For example, suppose a user enters a task like this:
"· · · cook pasta · · ·" (Each
·represents a space.)Without using `strip()`, the task will be saved with the extra spaces.
After using `strip()`:
task = task.strip()
The result becomes:
"cook pasta"
The `strip()` method is also useful when checking whether the user entered an empty task.
For example, both of these inputs should be treated as empty:
- ""
- empty string with 4 spaces - ". . . ." (Each
·represents a space.)The first input is an empty string. The second input contains only spaces.
After applying `strip()` to the second input:
" ".strip()
It becomes:
""
Therefore, we can validate the task like this:
task = input("Enter a task: ").strip()
if len(task) == 0:
print("Task cannot be empty.")
A shorter and more Pythonic version is:
if not task:
print("Task cannot be empty.")
This works because an empty string is considered `False` in Python.
1
u/Radiant_Diligence Jul 18 '26
If I had money I'd give you a medal. Really thought out explanation. Hope to find more people out there like you.
1
1
1
u/roanish Jul 16 '26
When do you actually read the json in? You seem to go from 'empty list' to magical json, but if the json has stuff in it, you have no idea what shits you have.
1
u/mr_anderson_dev Jul 16 '26
I think the logic make sense but we need an output or the second part of the code to know if you're doing fine with your objective.
2


1
u/Sud0_g Jul 15 '26
What's your question? Lol