-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject 3 .py
More file actions
57 lines (49 loc) · 1.69 KB
/
Copy pathproject 3 .py
File metadata and controls
57 lines (49 loc) · 1.69 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
# To-do list
tasks = []
def add_task(task):
task_id = len(tasks) + 1
tasks.append({"id": task_id, "task": task, "completed": False})
print(f"Task '{task}' added.")
def view_tasks():
for task in tasks:
status = "Completed" if task["completed"] else "Pending"
print(f"{task['id']}. {task['task']} - {status}")
def mark_completed(task_id):
for task in tasks:
if task["id"] == task_id:
task["completed"] = True
print(f"{task['id']}.'{task['task']}' Marked As Completed.")
return
print("Task not found.")
def delete_task(task_id):
global tasks
tasks = [task for task in tasks if task["id"] != task_id]
print(f"Task {task_id} deleted.")
#interface
def main():
while True:
print("\nTo-Do List Application")
print("1. Add a new task")
print("2. View all tasks")
print("3. Mark a task as completed")
print("4. Delete a task")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == '1':
task = input("Enter the task: ")
add_task(task)
elif choice == '2':
view_tasks()
elif choice == '3':
task_id = int(input("Enter the task ID to mark as completed: "))
mark_completed(task_id)
elif choice == '4':
task_id = int(input("Enter the task ID to delete: "))
delete_task(task_id)
elif choice == '5':
print("EXITING THE APPLICATION.")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()