command = argsline in the file to this block:
exitkills the program execution with the ID of what we pass in as an argument, 0 is successful exit, anything greater than 0 is unsuccessful exit
args = sys.argv
taskswhich is visible in this file to all functions.
listblock, we want to now print the values stored inside
tasksvariable. If the values aren't present, we should print "No tasks present", if there are tasks, then we should print the elements inside
len()function to check if there is nothing in the variable.
tasks = to this line,
tasks = ["title|content"].
tasksvariable is stored during the runtime. It gets reset to the default variable when the program quits. We need to add file handling feature to store the task list.
tasksline to this to store an empty variable.
openfunction. We need to wrap that in a try-except block.
cat tasks.txt, we come to know that the content of the file is this.
rm tasks.txt, or, delete the file manually if you are on windows.
task = title + content, we need this,
task = title + "|" + content.
if len(tasks)==0by this.
for task in tasks, we need to loop using
for i in range(len(tasks))is the way to go. The only difference is that we have to then fetch the task as
tasks[i]rather than just
task, because now, there is no such variable as
python tasks4.py removeinstead of
python tasks4.py remove 0, then our program should complain about an error, the same is the case with add, if the user doesn't give both title and content, that's an error and it should be handled appropriately.
task_idvariable to an integer. Change it to this below statement.
tasksvariable to our file, we add a "\n" to each element using the list comprehension mechanism.