-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
197 lines (162 loc) · 6.41 KB
/
app.py
File metadata and controls
197 lines (162 loc) · 6.41 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
"""
Simple Todo List Application
A command-line todo list manager for learning Git workflows
"""
class TodoList:
def __init__(self):
self.todos = []
def add_todo(self, task):
"""Add a new todo item"""
self.todos.append({"task": task, "completed": False})
print(f"✓ Added: {task}")
def list_todos(self):
"""Display all todos"""
if not self.todos:
print("No todos yet! Add one to get started.")
return
print("\n=== Your Todos ===")
for idx, todo in enumerate(self.todos, 1):
status = "✓" if todo["completed"] else "○"
print(f"{idx}. [{status}] {todo['task']}")
print()
def complete_todo(self, index):
"""Mark a todo as completed"""
if 0 <= index < len(self.todos):
self.todos[index]["completed"] = True
print(f"✓ Completed: {self.todos[index]['task']}")
else:
print("Invalid todo number!")
def delete_todo(self, index):
"""Delete a todo item"""
if 0 <= index < len(self.todos):
task = self.todos.pop(index)
print(f"✗ Deleted: {task['task']}")
else:
print("Invalid todo number!")
def main():
"""Main application loop"""
todo_list = TodoList()
print("=" * 40)
print(" Welcome to Git Workshop Todo App!")
print("=" * 40)
while True:
print("\nCommands: [a]dd, [l]ist, [c]omplete, [d]elete, [q]uit")
choice = input("What would you like to do? ").lower().strip()
if choice == 'a':
task = input("Enter todo: ")
todo_list.add_todo(task)
elif choice == 'l':
todo_list.list_todos()
elif choice == 'c':
todo_list.list_todos()
try:
num = int(input("Which todo to complete? ")) - 1
todo_list.complete_todo(num)
except ValueError:
print("Please enter a valid number!")
elif choice == 'd':
todo_list.list_todos()
try:
num = int(input("Which todo to delete? ")) - 1
todo_list.delete_todo(num)
except ValueError:
print("Please enter a valid number!")
elif choice == 'q':
print("Goodbye!")
break
else:
print("Invalid command!")
if __name__ == "__main__":
main()
class UserAuth:
def __init__(self):
self.users = {}
def register(self, username, password):
"""Register a new user"""
if username in self.users:
print("User already exists!")
return False
self.users[username] = password
return True
def login(self, username, password):
"""Login a user"""
if username not in self.users:
print("User not found!")
return False
if self.users[username] == password:
print(f"Welcome back, {username}!")
return True
print("Invalid password!")
return False
def validate_password(self, password):
"""Validate password strength"""
if len(password) < 8:
return False
return True
def print_header():
"""Print a nice header"""
print("╔════════════════════════════════════════╗")
print("║ Git Workshop Todo List Manager ║")
print("╔════════════════════════════════════════╗")
def print_menu():
"""Print menu options"""
print("\n┌─ Menu ─────────────────────────┐")
print("│ [a]dd - Add a new todo │")
print("│ [l]ist - List all todos │")
print("│ [c]omplete - Mark as done │")
print("│ [d]elete - Remove a todo │")
print("│ [q]uit - Exit program │")
print("└────────────────────────────────┘")
def save_to_file(todos, filename="todos.txt"):
"""Save todos to a file"""
with open(filename, 'w') as f:
for idx, todo in enumerate(todos, 1):
status = "DONE" if todo["completed"] else "TODO"
f.write(f"{idx}. [{status}] {todo['task']}\n")
print(f"✓ Saved to {filename}")
class UserAuth:
def __init__(self):
self.users = {}
def register(self, username, password):
"""Register a new user"""
if username in self.users:
print("User already exists!")
return False
self.users[username] = password
return True
def login(self, username, password):
"""Login a user"""
if username not in self.users:
print("User not found!")
return False
if self.users[username] == password:
print(f"Welcome back, {username}!")
return True
print("Invalid password!")
return False
def validate_password(self, password):
"""Validate password strength"""
if len(password) < 8:
return False
return True
def print_header():
"""Print a nice header"""
print("╔════════════════════════════════════════╗")
print("║ Git Workshop Todo List Manager ║")
print("╔════════════════════════════════════════╗")
def print_menu():
"""Print menu options"""
print("\n┌─ Menu ─────────────────────────┐")
print("│ [a]dd - Add a new todo │")
print("│ [l]ist - List all todos │")
print("│ [c]omplete - Mark as done │")
print("│ [d]elete - Remove a todo │")
print("│ [q]uit - Exit program │")
print("└────────────────────────────────┘")
def save_to_file(todos, filename="todos.txt"):
"""Save todos to a file"""
with open(filename, 'w') as f:
for idx, todo in enumerate(todos, 1):
status = "DONE" if todo["completed"] else "TODO"
f.write(f"{idx}. [{status}] {todo['task']}\n")
print(f"✓ Saved to {filename}")