-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.py
More file actions
54 lines (42 loc) · 1.13 KB
/
Copy pathtodo.py
File metadata and controls
54 lines (42 loc) · 1.13 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
def show_menu():
print("\n--- TO-DO LIST ---")
print("1. Add task")
print("2. View tasks")
print("3. Delete task")
print("4. Exit")
def add_task(tasks):
task = input("Enter task: ")
tasks.append(task)
print("Task added!")
def view_tasks(tasks):
if not tasks:
print("No tasks found.")
else:
print("\nYour Tasks:")
for i, task in enumerate(tasks, start=1):
print(f"{i}. {task}")
def delete_task(tasks):
view_tasks(tasks)
try:
task_no = int(input("Enter task number to delete: "))
tasks.pop(task_no - 1)
print("Task deleted!")
except:
print("Invalid input!")
def main():
tasks = []
while True:
show_menu()
choice = input("Choose an option: ")
if choice == "1":
add_task(tasks)
elif choice == "2":
view_tasks(tasks)
elif choice == "3":
delete_task(tasks)
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid choice!")
main()