Codepath

Greeting

TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)

Problem Highlights

  • 💡 Difficulty: Easy
  • Time to complete: 5 mins
  • 🛠️ Topics: Functions, Strings, Parameters

U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Q: What should the function greeting() do?

    • A: The function should take a single string parameter name and print a specific greeting message incorporating the given name.
  • Q: What should the output look like?

    • A: The output should be a single line of text: "Welcome to The Hundred Acre Wood <name>! My name is Christopher Robin."
  • Q: Are there any constraints on the input?

    • A: The input will always be a string, representing the name of the person being greeted.
  • The function greeting() should take a single parameter, name, and print a specific greeting message that includes the provided name.

HAPPY CASE
Input: "Michael"
Expected Output: Welcome to The Hundred Acre Wood Michael! My name is Christopher Robin.

Input: "Winnie the Pooh"
Expected Output: Welcome to The Hundred Acre Wood Winnie the Pooh! My name is Christopher Robin.

EDGE CASE
Input: " (empty string)
Expected Output: Welcome to The Hundred Acre Wood ! My name is Christopher Robin.

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Define a function that takes a parameter and prints a formatted string using that parameter.

1. Define the function `greeting(name)`.
2. Use the `print()` function to display the string "Welcome to The Hundred Acre Wood {name}! My name is Christopher Robin." using the provided name.

⚠️ Common Mistakes

  • Incorrectly formatting the string (ensure it matches exactly).
  • Forgetting to pass the parameter to the function.

I-mplement

Implement the code to solve the algorithm.

def greeting(name):
    print(f"Welcome to The Hundred Acre Wood {name}! My name is Christopher Robin.")
Fork me on GitHub