-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto_do_checklist_python_list.py
More file actions
132 lines (109 loc) · 3.43 KB
/
to_do_checklist_python_list.py
File metadata and controls
132 lines (109 loc) · 3.43 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
"""
To-Do List Application using Python Lists.
Author: Chaitanya Dasadiya
GitHub: https://github.com/cdasadiya
LinkedIn: https://in.linkedin.com/in/chaitanya-dasadiya
"""
# -------------------------------
# To-Do List Application (Lists)
# -------------------------------
# Initial checklist (demo data)
checklist = [
"Wake up early",
"Workout",
"Read 20 pages",
"Complete Python project",
"Attend meetings",
"Plan next day"
]
# Result lists
completed_tasks = []
incomplete_tasks = []
def display_tasks(tasks, title):
print(f"\n{title}")
print("-" * len(title))
for i, task in enumerate(tasks, start=1):
print(f"{i}. {task}")
if not tasks:
print("No tasks")
def mark_tasks():
if not checklist:
print("\nNo tasks available to mark.")
return
# Iterate over a copy to safely modify original list
for task in checklist[:]:
while True:
status = input(f"\nDid you complete '{task}'? (y/n): ").strip().lower()
if status == 'y':
completed_tasks.append(task)
checklist.remove(task)
break
elif status == 'n':
incomplete_tasks.append(task)
checklist.remove(task)
break
else:
print("Invalid input. Enter 'y' or 'n'.")
def add_task():
task = input("\nEnter new task: ").strip()
if task and task.lower() not in {item.lower() for item in checklist}:
checklist.append(task)
print("Task added.")
else:
print("Invalid or duplicate task.")
def remove_task():
if not checklist:
print("\nChecklist is empty. Nothing to remove.")
return
display_tasks(checklist, "Current Checklist")
try:
idx = int(input("Enter task number to remove: "))
if idx < 1 or idx > len(checklist):
raise IndexError
removed = checklist.pop(idx - 1)
print(f"Removed: {removed}")
except (ValueError, IndexError):
print("Invalid selection.")
def advanced_list_ops():
print("\n--- Advanced List Operations Demo ---")
bonus_tasks = ["Meditation", "Journaling"]
checklist.extend(bonus_tasks)
checklist.insert(0, "Check emails")
checklist.sort()
checklist.reverse()
print("Count of 'Workout':", checklist.count("Workout"))
if "Workout" in checklist:
print("Index of 'Workout':", checklist.index("Workout"))
def summary():
display_tasks(completed_tasks, "Completed Tasks")
display_tasks(incomplete_tasks, "Incomplete Tasks")
def menu():
while True:
print("\n====== TO-DO MENU ======")
print("1. View Checklist")
print("2. Add Task")
print("3. Remove Task")
print("4. Mark Tasks (Complete/Incomplete)")
print("5. Advanced List Operations Demo")
print("6. View Summary")
print("7. Exit")
choice = input("Choose an option: ").strip()
if choice == '1':
display_tasks(checklist, "Checklist")
elif choice == '2':
add_task()
elif choice == '3':
remove_task()
elif choice == '4':
mark_tasks()
elif choice == '5':
advanced_list_ops()
elif choice == '6':
summary()
elif choice == '7':
print("Exiting application.")
break
else:
print("Invalid choice.")
if __name__ == "__main__":
menu()