244. Python Program to Make a To-Do List with Commands
MediumPhase 2 · Practice
This one takes a few steps. You know everything it uses: a while loop, lists and string slices.
Overview
A to-do list keeps track of the jobs you still have to do. Many apps work like this one: you type a short command, and the app answers it.
Problem Statement
Thandi wants a to-do list that runs on commands. The list starts empty. Tasks get a number from 1, in the order they are added. Read one command per line until a line says end. The commands are:
add <task>: add the task at the end of the list. PrintAdded: <task>. A task can have spaces, likebuy milk.done <number>: mark that task as done. PrintDone: <task>. If the task is already done, printAlready done: <task>. If there is no task with that number, printNo task <number>.show: print every task on its own line, in the order they were added. A done task looks like1. [x] buy milk. A task that is not done looks like1. [ ] buy milk, with one space between the square brackets. If the list is empty, printNo tasks.
Commands are in small letters. For any other line, like Add milk or remove 1, print Unknown command. Print nothing for end.
Examples
Example 1. Input:
add buy milk
add call grandma
add pay rent
done 2
show
end
gives:
Added: buy milk
Added: call grandma
Added: pay rent
Done: call grandma
1. [ ] buy milk
2. [x] call grandma
3. [ ] pay rent
Why: the three tasks get the numbers 1, 2 and 3. Only task 2 is done, so only task 2 has an x.
Example 2. Input:
show
add water the plants
done 1
done 1
done 4
clean
show
end
gives:
No tasks
Added: water the plants
Done: water the plants
Already done: water the plants
No task 4
Unknown command
1. [x] water the plants
Why: the list is empty at first, so show prints No tasks. Task 1 is marked done twice, so the second time says Already done. There is no task 4, and clean is not a command.
Input
One command per line, in the formats above. The last line is always end. Every add has a task after it. The number after done is always a whole number, but it can be 0 or bigger than the number of tasks. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
One line for each command, except show, which prints one line for each task. The tests try 7 different inputs, also an empty list and task numbers that do not exist.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.