-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTo-Do List.py
More file actions
76 lines (68 loc) · 2.12 KB
/
To-Do List.py
File metadata and controls
76 lines (68 loc) · 2.12 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
def display_menu():
print("\nTo-Do List Menu:")
print("1. View tasks")
print("2. Add task")
print("3. Mark task as completed")
print("4. Delete task")
print("5. Exit")
def view_tasks(tasks):
if not tasks:
print("No tasks in the list.")
return
print("\nTasks:")
for idx, task in enumerate(tasks, 1):
status = "✓" if task['completed'] else "✗"
print(f"{idx}. [{status}] {task['description']}")
def add_task(tasks):
desc = input("Enter task description: ").strip()
if desc:
tasks.append({'description': desc, 'completed': False})
print("Task added.")
else:
print("Empty task description not added.")
def mark_completed(tasks):
if not tasks:
print("No tasks to mark.")
return
try:
num = int(input("Enter task number to mark as completed: "))
if 1 <= num <= len(tasks):
tasks[num-1]['completed'] = True
print("Task marked as completed.")
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
def delete_task(tasks):
if not tasks:
print("No tasks to delete.")
return
try:
num = int(input("Enter task number to delete: "))
if 1 <= num <= len(tasks):
removed = tasks.pop(num-1)
print(f"Deleted task: {removed['description']}")
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
def main():
tasks = []
while True:
display_menu()
choice = input("Choose an option: ").strip()
if choice == '1':
view_tasks(tasks)
elif choice == '2':
add_task(tasks)
elif choice == '3':
mark_completed(tasks)
elif choice == '4':
delete_task(tasks)
elif choice == '5':
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()