TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Q: What should the function print_todo_list()
do?
tasks
and print each task on a new line with a numbered format, preceded by the header "Pooh's To Dos:".Q: How should the tasks be numbered?
1. Task 1
, 2. Task 2
, etc.Q: What happens if the list of tasks is empty?
The function print_todo_list(
) should take a list of strings tasks
and print each task on a new line, prefixed with its position in the list.
HAPPY CASE
Input: ["Count all the bees in the hive", "Chase all the clouds from the sky", "Think", "Stoutness Exercises"]
Expected Output:
Pooh's To Dos:
1. Count all the bees in the hive
2. Chase all the clouds from the sky
3. Think
4. Stoutness Exercises
EDGE CASE
Input: []
Expected Output:
Pooh's To Dos:
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Define a function that prints each task with its corresponding number in the list.
1. Define the function `print_todo_list(tasks)`.
2. Print the header "Pooh's To Dos:".
3. Iterate over the range of indices from 1 to len(tasks).
4. Print each task in the format "i. task" where `i` is the current index.
⚠️ Common Mistakes
Implement the code to solve the algorithm.
def print_todo_list(tasks):
# Print the header
print("Pooh's To Dos:")
# Iterate over the range of indices from 1 to len(tasks)
for i in range(1, len(tasks) + 1):
# Print each task in the specified format
print(f"{i}. {tasks[i - 1]}")