-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
81 lines (71 loc) · 2.31 KB
/
app.py
File metadata and controls
81 lines (71 loc) · 2.31 KB
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
80
81
from db import TodoDatabase
class TodoApp:
def __init__(self):
self.db = TodoDatabase()
def display_todos(self):
todos = self.db.get_all()
if not todos:
print("\n📝 No todos yet!\n")
return
print("\n" + "="*50)
print("📋 YOUR TODOS")
print("="*50)
for todo in todos:
todo_id, title, is_completed = todo
status = "✓" if is_completed else "○"
print(f"{status} [{todo_id}] {title}")
print("="*50 + "\n")
def add_todo(self):
title = input("Enter todo title: ").strip()
if title:
self.db.add_todo(title)
print(f"✓ Todo added!\n")
else:
print("❌ Title cannot be empty!\n")
def complete_todo(self):
self.display_todos()
try:
todo_id = int(input("Enter todo ID to mark complete: "))
self.db.update_todo(todo_id, is_completed=1)
print("✓ Todo marked complete!\n")
except ValueError:
print("❌ Invalid ID!\n")
def delete_todo(self):
self.display_todos()
try:
todo_id = int(input("Enter todo ID to delete: "))
self.db.delete_todo(todo_id)
print("✓ Todo deleted!\n")
except ValueError:
print("❌ Invalid ID!\n")
def show_menu(self):
print("\n" + "="*50)
print("📌 TODO MANAGER")
print("="*50)
print("1. View todos")
print("2. Add todo")
print("3. Mark as complete")
print("4. Delete todo")
print("5. Exit")
print("="*50)
def run(self):
while True:
self.show_menu()
choice = input("Choose an option (1-5): ").strip()
if choice == '1':
self.display_todos()
elif choice == '2':
self.add_todo()
elif choice == '3':
self.complete_todo()
elif choice == '4':
self.delete_todo()
elif choice == '5':
print("\n👋 Goodbye!\n")
self.db.close()
break
else:
print("❌ Invalid choice! Try again.\n")
if __name__ == "__main__":
app = TodoApp()
app.run()