The Personal Planner
Build a simple task planner that works in one running session. The user should be able to add tasks, list them and mark one as completed using a menu.
Reveal a hint (from the printed book)
A task can be a small dictionary with keys such as title and done. Keep numbering consistent with the displayed list.
Reveal a worked Python solution
One possible implementation. Check the book's tests and try an extension after comparing.
"""Challenge 91: Personal Planner (session-only data)."""
def add_task(tasks, title):
if not title.strip():
return False
tasks.append({"title": title.strip(), "done": False})
return True
def complete_task(tasks, number):
if 1 <= number <= len(tasks):
tasks[number - 1]["done"] = True
return True
return False
def list_tasks(tasks):
return [f"{i}. [{'x' if t['done'] else ' '}] {t['title']}"
for i, t in enumerate(tasks, 1)]
def main():
tasks = []
while True:
command = input("add / list / done / quit: ").strip().lower()
if command == "add":
if not add_task(tasks, input("Task: ")):
print("Enter a task name.")
elif command == "list":
print("\n".join(list_tasks(tasks)) or "No tasks yet.")
elif command == "done":
number = input("Task number: ")
if not number.isdigit() or not complete_task(tasks, int(number)):
print("Unknown task number.")
elif command == "quit":
break
else:
print("Choose add, list, done or quit.")
if __name__ == "__main__":
main()Save this Python file ↓