0% found this document useful (0 votes)
27 views4 pages

Computer Project 2024-25 (CP)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Computer Project 2024-25 (CP)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Project: To-Do List Organizer

Code:
# Todo List Organizer in Python
# This program allows users to add, view, and remove tasks from a to-do list.

# Initializing an empty list to store tasks


todo_list = []

# Function to display menu options


def display_menu():
print("\nTodo List Organizer")
print("1. View Todo List")
print("2. Add a Task")
print("3. Remove a Task")
print("4. Exit\n")

# Function to view all tasks


def view_tasks():
if len(todo_list) == 0:
print("Your todo list is empty.")
else:
print("\nHere are your tasks:")
for i, task in enumerate(todo_list, 1):
print(f"{i}. {task}")

# Function to add a new task


def add_task():
task = input("Enter a new task: ")
todo_list.append(task)
print(f"Task '{task}' added to the list!")

# Function to remove a task by its number


def remove_task():
try:
task_number = int(input("Enter the task number to remove: "))
if 1 <= task_number <= len(todo_list):
removed_task = todo_list.pop(task_number - 1)
print(f"Task '{removed_task}' removed from the list!")
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")

# Main loop to interact with the user


def main():
while True:
display_menu()
choice = input("Choose an option: ")

if choice == '1':
view_tasks()
elif choice == '2':
add_task()
elif choice == '3':
remove_task()
elif choice == '4':
print("Exiting Todo List Organizer. Goodbye!")
break
else:
print("Invalid choice. Please try again.")

# Starting the program


if __name__ == "__main__":
main()
Documentation:

1. Introduction:

This project is a Python-based Todo List Organizer that allows users to


manage their tasks efficiently. The user can perform three main actions: view
tasks, add tasks, and remove tasks. The program uses basic control
structures, functions, and list handling in Python.

2. Code Explanation:

- The program starts by defining an empty list called `todo_list`, where tasks
are stored.
- A menu is displayed using the `display_menu()` function to allow the user to
choose actions.
- The user can view the tasks with the `view_tasks()` function, which lists the
tasks or informs the user if the list is empty.
- The `add_task()` function prompts the user to input a new task, which is
then appended to the `todo_list`.
- To remove a task, the `remove_task()` function takes a task number as input,
checks its validity, and removes the corresponding task from the list.
- The program runs in an infinite loop, allowing continuous user interaction
until the user chooses to exit by selecting option `4`.

3. Functions:

- `display_menu()`: Displays the main menu options.


- `view_tasks()`: Displays the list of tasks or informs the user if no tasks are
available.
- `add_task()`: Adds a task to the to-do list.
- `remove_task()`: Removes a task based on the task number provided by the
user.
- `main()`: The main loop that controls the flow of the program based on user
input.
Output:

You might also like