Lazo Lab Sign up

App 2: To-Do List Manager / Build the to-do app

Lesson 5 of 10

Picking a task by number

Done and delete both need the user to choose a task number. Write one helper that asks, checks it's valid, and returns the list position (or None).

Key points

  • Users count from 1, lists from 0
  • Validate before using
  • One helper, used twice
def pick_task():
    list_tasks()
    num = input("Number: ").strip()
    if num.isdigit() and 1 <= int(num) <= len(tasks):
        return int(num) - 1
    print("That number isn't on the list.")
    return None

Your turn

Write pick_task() and test it with good and bad numbers.

Watch a video on thisOpens YouTube search results for “Picking a task by number” in a new tab

Quiz · +10 XP

If the user types 1, which list index does pick_task return?

Log in to save progress and earn XP.