-
Notifications
You must be signed in to change notification settings - Fork 0
/
TO- DO list.py
54 lines (47 loc) · 1.48 KB
/
TO- DO list.py
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
# Simple To-Do List App
def show_menu():
print("\n--- To-Do List Menu ---")
print("1. View To-Do List")
print("2. Add Task")
print("3. Remove Task")
print("4. Exit")
def view_tasks(tasks):
if not tasks:
print("\nNo tasks in your to-do list.")
else:
print("\nYour To-Do List:")
for idx, task in enumerate(tasks, 1):
print(f"{idx}. {task}")
def add_task(tasks):
task = input("Enter the task: ")
tasks.append(task)
print(f"Task '{task}' added successfully!")
def remove_task(tasks):
view_tasks(tasks)
try:
task_num = int(input("\nEnter the task number to remove: "))
if 1 <= task_num <= len(tasks):
removed_task = tasks.pop(task_num - 1)
print(f"Task '{removed_task}' removed successfully!")
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
def main():
tasks = []
while True:
show_menu()
choice = input("Choose an option (1-4): ")
if choice == '1':
view_tasks(tasks)
elif choice == '2':
add_task(tasks)
elif choice == '3':
remove_task(tasks)
elif choice == '4':
print("Exiting the To-Do List App. Goodbye!")
break
else:
print("Invalid choice. Please select a valid option.")
if __name__ == "__main__":
main()