-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (47 loc) · 1.35 KB
/
main.py
File metadata and controls
53 lines (47 loc) · 1.35 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
# todo.py
def show_menu():
print("\n===== TO-DO LIST MENU =====")
print("1. View tasks")
print("2. Add task")
print("3. completed task")
print("4. Exit")
def view_tasks(tasks):
if not tasks:
print("\nNo tasks in the list.")
else:
print("\nTasks:")
for i, task in enumerate(tasks, start=1):
print(f"{i}. {task}")
def add_task(tasks):
task = input("Enter a new task: ")
tasks.append(task)
print("Task added.")
def completed_task(tasks):
view_tasks(tasks)
try:
index = int(input("Enter the task number to remove: ")) - 1
if 0 <= index < len(tasks):
removed = tasks.pop(index)
print(f"Removed task: {removed}")
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: ")
if choice == '1':
view_tasks(tasks)
elif choice == '2':
add_task(tasks)
elif choice == '3':
completed_task(tasks)
elif choice == '4':
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()