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_catchphrase()
do?
character
and print the corresponding catchphrase from a predefined set. If the character is not recognized, it should print a default message indicating that the catchphrase is unknown.Q: What characters are expected, and what are their catchphrases?
"Pooh"
: "Oh bother!"
"Tigger"
: "TTFN: Ta-ta for now!"
"Eeyore"
: "Thanks for noticing me."
"Christopher Robin"
: "Silly old bear."
Q: What should be done if the input character is not in the list?
"Sorry! I don't know <character>'s catchphrase!"
.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.
⚠️ Common Mistakes
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!")