- 
                Notifications
    
You must be signed in to change notification settings  - Fork 266
 
Catchphrase
        kyra-ptn edited this page Aug 25, 2024 
        ·
        5 revisions
      
    TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)
- 💡 Difficulty: Easy
 - ⏰ Time to complete: 5 mins
 - 🛠️ Topics: Functions, Strings, Conditionals
 
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_catchphrase()should take a single parameter, character, and print the corresponding catchphrase based on the given character. If the character does not match any in the table, it should print a default message. 
HAPPY CASE
Input: "Pooh"
Expected Output: Oh bother!
Input: "Tigger"
Expected Output: TTFN: Ta-ta for now!
EDGE CASE
Input: "Piglet"
Expected Output: Sorry! I don't know Piglet's catchphrase!
Input: " (empty string)
Expected Output: Sorry! I don't know 's catchphrase!
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Define a function that uses conditionals to match the input character to a predefined set of catchphrases, printing the appropriate message.
1. Define the function `print_catchphrase(character)`.
2. Use conditional statements to check the value of `character`.
3. Print the corresponding catchphrase if the character matches one from the table.
4. If the character does not match any in the table, print a default message.- Incorrectly formatting the strings (ensure they match exactly).
 - Forgetting to handle characters not listed in the table.
 
Implement the code to solve the algorithm.
def print_catchphrase(character):
    if character == "Pooh":
        print("Oh bother!")
    elif character == "Tigger":
        print("TTFN: Ta-ta for now!")
    elif character == "Eeyore":
        print("Thanks for noticing me.")
    elif character == "Christopher Robin":
        print("Silly old bear.")
    else:
        print(f"Sorry! I don't know {character}'s catchphrase!")