/ demo.py
demo.py
 1  import sys
 2  
 3  todos = []
 4  
 5  def show_todos():
 6      if not todos:
 7          print("No tasks in the list!")
 8      else:
 9          for i, task in enumerate(todos, start=1):
10              print(f"{i}. {task}")
11  
12  def add_todo():
13      task = input("Enter the task: ")
14      todos.append(task)
15      print(f"'{task}' added to the list!")
16  
17  def remove_todo():
18      show_todos()
19      try:
20          index = int(input("Enter the number of the task to remove: "))
21          removed = todos.pop(index - 1)
22          print(f"'{removed}' removed from the list!")
23      except (ValueError, IndexError):
24          print("Invalid task number!")
25  
26  def main():
27      while True:
28          print("\nTo-Do List:")
29          print("1. Show tasks")
30          print("2. Add task")
31          print("3. Remove task")
32          print("4. Exit")
33          choice = input("Enter your choice: ")
34  
35          if choice == '1':
36              show_todos()
37          elif choice == '2':
38              add_todo()
39          elif choice == '3':
40              remove_todo()
41          elif choice == '4':
42              print("Exiting... Goodbye!")
43              sys.exit()
44          else:
45              print("Invalid choice! Try again.")
46  
47  if __name__ == "__main__":
48      main()