TIP102 Unit 5 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.
- 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?
get_player()
to the Player
class and use it to print a formatted string with details about two Player
objects.HAPPY CASE
Input: Create Player with "Yoshi" and "Super Blooper", another with "Bowser" and "Pirahna Prowler"
Output: "Match: Yoshi driving the Super Blooper vs Bowser driving the Pirahna Prowler"
Explanation: The `get_player()` method correctly formats the details of each player, and these details are used in the final print statement.
EDGE CASE
Input: Create Player with empty strings for character and kart
Output: "Match: driving the vs driving the "
Explanation: The `get_player()` method handles cases with empty strings gracefully, producing an empty output for character and kart.
Match what this problem looks like to known categories of problems, e.g. Linked List or Dynamic Programming, and strategies or patterns in those categories.
For class method problems, we want to consider the following approaches:
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Add a method to the Player
class to return a formatted string with the player's character and kart. Create a new player and use this method to generate a specific output.
1) Define the `get_player()` method within the `Player` class.
2) Inside `get_player()`, use an f-string to format the output as "<character> driving the <kart>".
3) Create a new instance `player_two` with "Bowser" as the character and "Pirahna Prowler" as the kart.
4) Use the `get_player()` method for both `player_one` and `player_two` to print the match statement.
⚠️ Common Mistakes
self
to access class attributes within the method.Implement the code to solve the algorithm.
class Player():
def __init__(self, character, kart):
self.character = character
self.kart = kart
self.items = []
def get_player(self):
return f"{self.character} driving the {self.kart}"
player_two = Player("Bowser", "Pirahna Prowler")
print(f"Match: {player_one.get_player()} vs {player_two.get_player()}")
Review the code by running specific example(s) and recording values (watchlist) of your code's variables along the way.
Evaluate the performance of your algorithm and state any strong/weak or future potential work.