Skip to content

Pooh's To Do's

LeWiz24 edited this page Aug 21, 2024 · 4 revisions

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.

  • Established a set (2-3) of test cases to verify their own solution later.
  • Established a set (1-2) of edge cases to verify their solution handles complexities.
  • Have fully understood the problem and have no clarifying questions.
  • Have you verified any Time/Space Constraints for this problem?
  • 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:

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]}")
Clone this wiki locally