Skip to main content

CLI Menus & Testable Cores

beginner12 min readLesson 51 of 169

The menu loop, input() limits in graders, and separating deciding from doing.

A command-line application is a loop: show options, read a choice, act, repeat.

while True:
    choice = menu()          # in real apps: input("> ")
    if choice == "list":
        show_tasks()
    elif choice == "add":
        add_task()
    elif choice == "quit":
        break
    else:
        print("unknown choice")

input() reads a line from the user โ€” but the sandbox (and any automated grader) cannot type at your program. That is why graded challenges isolate functions with parameters and returns, and menus are wired around them:

def add_task(tasks, text):
    tasks.append({"text": text, "done": False})
    return tasks

Separate the deciding from the doing and your CLI becomes testable โ€” the same lesson the capstone will grade you on.

Now practice

Task-Function DrillsThe pure logic of a task manager โ€” no menu, just functions.4 challenges ยท ยท ~30 min