-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjective2ToDoListApplication.py
More file actions
62 lines (55 loc) · 1.98 KB
/
objective2ToDoListApplication.py
File metadata and controls
62 lines (55 loc) · 1.98 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
# To-Do List Application
# Define the to-do list
todo_list = []
# Function to add a task to the to-do list
def add_task(task):
todo_list.append(task)
print(f'Task "{task}" has been added.')
# Function to view all tasks in the to-do list
def view_tasks():
if not todo_list:
print("Your to-do list is empty.")
else:
print("Your to-do list:")
for idx, task in enumerate(todo_list, start=1):
#Enumerate is a built-in function in python that allows you to keep track of the number of iterations(loops) in a loop.
print(f"{idx}. {task}")
# Function to delete a task from the to-do list
def delete_task(task_number):
try:
task = todo_list.pop(task_number - 1)
print(f'Task "{task}" has been deleted.')
except IndexError:
print("Invalid task number. Please try again.")
# Main function to run the to-do list manager
def todo_list_manager():
print("Welcome to the To-Do List Manager!")
while True:
print("\nOptions:")
print("1. Add a task")
print("2. View tasks")
print("3. Delete a task")
print("4. Exit")
try:
choice = int(input("Enter your choice: "))
except ValueError:
print("Invalid input. Please enter a number between 1 and 4.")
continue
if choice == 1:
task = input("Enter your task: ")
add_task(task)
elif choice == 2:
view_tasks()
elif choice == 3:
try:
task_number = int(input("Enter the task number to delete: "))
delete_task(task_number)
except ValueError:
print("Invalid input!!! Please enter a valid task number.")
elif choice == 4:
print("Thank you")
break
else:
print("Invalid choice!!! Please enter a number between 1 & 4.")
# Start the to-do list manager
todo_list_manager()