Pooh's To Do's - codepath/compsci_guides GitHub Wiki
TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)
Problem Highlights
- 💡 Difficulty: Easy
- ⏰ Time to complete: 5 mins
- 🛠️ Topics: Functions, Strings, Conditionals
U-nderstand
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?- A: The function should accept a list of strings
tasks
and print each task on a new line with a numbered format, preceded by the header "Pooh's To Dos:".
- A: The function should accept a list of strings
-
Q: How should the tasks be numbered?
- A: The tasks should be numbered starting from 1 and each task should appear on a new line in the format
1. Task 1
,2. Task 2
, etc.
- A: The tasks should be numbered starting from 1 and each task should appear on a new line in the format
-
Q: What happens if the list of tasks is empty?
- A: The function should only print the header "Pooh's To Dos:" and nothing else.
-
The function
print_todo_list(
) should take a list of stringstasks
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:
P-lan
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
- Forgetting to adjust the index when printing tasks.
I-mplement
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]}")