To-Do List Manager
Create a simple to-do list manager where users can add, view, and delete tasks from their to-do list. The program should provide a menu-driven interface for users to interact with their tasks.
Let's go through each function in the code and explain their purpose:
Create a variable tasks of list data type that contains no item.
add_task() :This function is responsible for adding a task to the tasks
list. It prompts the user to enter a new task using the input()
function. The entered task is then appended to the tasks
list using the append()
method. Finally, it prints a message to confirm that the task has been added successfully.
3.Function to view tasks
view_tasks()
: This function displays all the tasks in the tasks
list. It first checks if the list is empty using a conditional statement. If the list is not empty, it iterates over the tasks using the enumerate()
function. The enumerate()
function provides both the index and the value of each task in the list. It then prints each task along with its corresponding index number. If the list is empty, it prints a message indicating that the task list is empty.
4. Function to delete task
delete_task()
: This function allows the user to delete a task from the tasks
list. First, it calls the view_tasks()
function to display the current tasks. It then prompts the user to enter the number of the task they want to delete. The input is converted to an integer and subtracted by 1 to align with the zero-based indexing of the list. Next, it checks if the entered task index is valid by comparing it with the range of valid indices in the list. If the index is valid, it uses the pop()
method to remove the task at the specified index from the tasks
list. It also prints a message to confirm the deletion of the task. If the entered index is invalid, it prints an error message.
Creating a menu and calling the functions as per user's choice
Here, we are going to create a menu for the user to select the kind of task he wants to do.
Last updated