diff --git a/projects/ToDoList/README.md b/projects/ToDoList/README.md new file mode 100644 index 00000000..4a6aa938 --- /dev/null +++ b/projects/ToDoList/README.md @@ -0,0 +1,21 @@ +# ToDo List in Python 📒 + +This is a simple command-line ToDo List application written in Python. + +## Features + +- **Add Tasks:** You can add tasks to your ToDo list. Just type in your task when prompted. + +- **Remove Tasks:** You can remove tasks from your ToDo list. You will need to provide the task number (the number displayed next to each task when displaying tasks). + +- **Display Tasks:** You can display all tasks in your ToDo list in the order they were added. + +- **Quit:** You can quit the application at any time. + +## Usage + +To run the program, you will need Python installed on your computer. Once you have Python, you can run the program from the command line by navigating to the directory containing the Python file and running the following command: + +```bash +python to_do_list.py +python3 to_do_list.py \ No newline at end of file diff --git a/projects/ToDoList/to_do_list.py b/projects/ToDoList/to_do_list.py new file mode 100644 index 00000000..b6337e43 --- /dev/null +++ b/projects/ToDoList/to_do_list.py @@ -0,0 +1,68 @@ +def add_task(task): + todo_list.append(task) + print("Task added!") + +def remove_task(task_num): + if 0 <= task_num < len(todo_list): + del todo_list[task_num] + print("Task removed!") + else: + print("Invalid task number!") + +def display_tasks(): + if not todo_list: # If list is empty + print("No tasks to display.") + else: + for index, task in enumerate(todo_list, start=1): + print(f"{index}. {task}") + +def get_choice(): + while True: + try: + choice = int(input("Type a number: 1. Adding a task, 2. Removing a task, 3. Displaying tasks, 4. Quit: ")) + if 1 <= choice <= 4: + return choice + else: + print("Invalid choice. Try again.") + except ValueError: + print("Please enter a number between 1 and 4.") + +if __name__ == "__main__": + + todo_list = [] + + print("Welcome to ToDo List!") + + while True: + user_choice = get_choice() + + #Adding a task + if user_choice == 1: + new_task = input("Type a new task: ") + add_task(new_task) + + #Removing a task + elif user_choice == 2: + if not todo_list: # If list is empty + print("No tasks to remove.") + else: + task_num = int(input("Enter the task number to delete: ")) - 1 + remove_task(task_num) + + #Displaying tasks + elif user_choice == 3: + display_tasks() + + #Quit + elif user_choice == 4: + print("Goodbye!") + break + + +##################################### + +# CODE CONTRIBUTED BY: Ota Hina + +##################################### + + \ No newline at end of file