File size: 2,754 Bytes
2411b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys

# Simple Todo Application

class TodoApp:
    def __init__(self):
        self.todos = []  # List to store todo items, each as a dict {'task': str, 'completed': bool}

    def add_task(self, task):
        """Add a new task to the todo list."""
        if task:
            self.todos.append({'task': task, 'completed': False})
            print(f"Added task: {task}")
        else:
            print("Task cannot be empty.")

    def delete_task(self, index):
        """Delete a task by its index."""
        if 0 <= index < len(self.todos):
            deleted = self.todos.pop(index)
            print(f"Deleted task: {deleted['task']}")
        else:
            print("Invalid task index.")

    def mark_complete(self, index):
        """Mark a task as complete by its index."""
        if 0 <= index < len(self.todos):
            self.todos[index]['completed'] = True
            print(f"Marked as complete: {self.todos[index]['task']}")
        else:
            print("Invalid task index.")

    def list_tasks(self):
        """List all tasks with their status."""
        if not self.todos:
            print("No tasks available.")
        for i, todo in enumerate(self.todos):
            status = "Completed" if todo['completed'] else "Pending"
            print(f"{i + 1}. {todo['task']} - {status}")

    def run(self):
        """Run the todo application in a loop."""
        while True:
            print("\nTodo App Menu:")
            print("1. Add Task")
            print("2. Delete Task")
            print("3. Mark Task as Complete")
            print("4. List Tasks")
            print("5. Quit")
            choice = input("Enter your choice (1-5): ").strip()

            if choice == '1':
                task = input("Enter task: ").strip()
                self.add_task(task)
            elif choice == '2':
                self.list_tasks()
                try:
                    index = int(input("Enter task number to delete: ")) - 1
                    self.delete_task(index)
                except ValueError:
                    print("Invalid input. Please enter a number.")
            elif choice == '3':
                self.list_tasks()
                try:
                    index = int(input("Enter task number to mark complete: ")) - 1
                    self.mark_complete(index)
                except ValueError:
                    print("Invalid input. Please enter a number.")
            elif choice == '4':
                self.list_tasks()
            elif choice == '5':
                print("Exiting Todo App.")
                sys.exit(0)
            else:
                print("Invalid choice. Please try again.")

if __name__ == "__main__":
    app = TodoApp()
    app.run()