You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

62 lines
1.4 KiB

  1. class Todo:
  2. def __init__(self, contents, done):
  3. self.contents = contents
  4. self.done = done
  5. class TodoList:
  6. def __init__(self):
  7. self.todos = []
  8. def add(self, contenu):
  9. self.todos.append(Todo(contenu, False))
  10. def mark_as_done(self, i):
  11. self.todos[i - 1].done = True
  12. def mark_as_not_done(self, i):
  13. self.todos[i - 1].done = False
  14. def show(self):
  15. if not self.todos:
  16. print("nothing yet")
  17. i = 1
  18. for todo in self.todos:
  19. if todo.done:
  20. print(i, "[x]", todo.contents)
  21. else:
  22. print(i, "[ ]", todo.contents)
  23. i += 1
  24. def parse_answer(answer):
  25. if answer.startswith("+ "):
  26. return "add", answer[2:]
  27. if answer.startswith("- "):
  28. return "remove", int(answer[2:])
  29. if answer.startswith("x "):
  30. return "done", int(answer[2:])
  31. if answer.startswith("o "):
  32. return "undo", int(answer[2:])
  33. return "error", ""
  34. def main():
  35. todo_list = TodoList()
  36. while True:
  37. todo_list.show()
  38. answer = input("+ / x / o ?\n")
  39. command, arg = parse_answer(answer)
  40. if command == "add":
  41. todo_list.add(arg)
  42. if command == "done":
  43. todo_list.mark_as_done(arg)
  44. if command == "undo":
  45. todo_list.mark_as_not_done(arg)
  46. if command == "error":
  47. print("error")
  48. if __name__ == "__main__":
  49. main()