tasks = []
def ShowMenu():
print("=== Personal assistant main menu ===")
print("1. Add task")
print("2. Show all tasks")
print("3. Mark task as done")
print("4. Remove task")
print("5. Exit")
def ReadUserInput(TitleString="Enter row number you prefer: "):
while True:
try:
choice = int(input(TitleString))
except ValueError:
print("Please enter a number!")
else:
return choice
def AddTask():
newTask = input("Enter new task: ").strip()
if newTask:
tasks.append(newTask)
else:
print("Please enter a valid task!")
def ShowTasks():
print(f"You have {len(tasks)} tasks!")
if(tasks):
for i,task in enumerate(tasks):
print(f"{1 + i}. {task}")
def MarkTaskAsDone():
ShowTasks()
if tasks:
choice = ReadUserInput("Enter code of task you want to mark as done: ")
if 1 <= choice <= len(tasks):
completedTask = tasks.pop(choice-1)
print(f"You have done {completedTask} and it was deleted")
else:
print("Incorrect task number!")
def DeleteTask():
ShowTasks()
if tasks:
choice = ReadUserInput("Enter code of task you want to delete: ")
if 1 <= choice <= len(tasks):
delTask = tasks.pop(choice-1)
print(f"Task {delTask} was deleted")
else:
print("Incorrect task number!")
while True:
ShowMenu()
choice = ReadUserInput()
if(choice == 1):
AddTask()
elif choice == 2:
ShowTasks()
input("Press enter to continue...")
elif choice == 3:
MarkTaskAsDone()
input("Press enter to continue...")
elif choice == 4:
DeleteTask()
input("Press enter to continue...")
elif choice == 5:
break