Advertisement
SimonTDigger

python beginners course project code

Sep 5th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. exit = False
  2. todo_items = []
  3. def get_argument(command):
  4. command_name, argument = command.split(" ", maxsplit=1)
  5. return argument
  6. def handle_add_command(command):
  7. argument = get_argument(command)
  8. print(f"Adding task: {argument}")
  9. todo_items.append(argument)
  10. def handle_delete_command(command):
  11. argument = get_argument(command)
  12. print(f"Deleting task: {argument}")
  13. todo_items.pop(int(argument) - 1)
  14. def handle_list_command():
  15. index = 0
  16. for todo_item in todo_items:
  17. index += 1
  18. print(f"{index}. {todo_item}")
  19. def process_command(command):
  20. exit = False
  21. if command.startswith("exit"):
  22. exit = True
  23. elif command.startswith("add"):
  24. handle_add_command(command)
  25. elif command.startswith("delete"):
  26. # delete task
  27. handle_delete_command(command)
  28. elif command.startswith("list"):
  29. handle_list_command()
  30. else:
  31. print("Command not recognized")
  32. return exit
  33. while not exit:
  34. command = input("Enter command: ")
  35. exit = process_command(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement