Codepath

Planning App

Unit 2 Session 1 (Click for link to problem statements)

U-nderstand

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

  • Q: What is the problem asking for?

    • A: The problem asks to return the schedule information for a specific artist if they exist in the provided festival schedule dictionary, otherwise return a message indicating the artist was not found.
  • Q: What are the inputs?

    • A: A string artist and a dictionary festival_schedule mapping artist's names to their schedule details (day, time, stage).
  • Q: What are the outputs?

    • A: A dictionary containing the artist's schedule details or a message indicating the artist was not found.
  • Q: What should be returned if the artist is not in the schedule?

    • A: A dictionary with a single key-value pair: {"message": "Artist not found"}.

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Check if the artist exists in the festival schedule dictionary and return the corresponding information or an error message if the artist is not found.

1) Check if `artist` is a key in `festival_schedule`.
   - If true, return the value (schedule details) corresponding to the `artist`.
   - If false, return the dictionary `{"message": "Artist not found"}`.

⚠️ Common Mistakes

  • Ensure that the artist name is checked correctly in the dictionary.
  • Handle cases where the artist is not found by returning the specified error message.

I-mplement

def get_artist_info(artist, festival_schedule):
    # Check if the artist is in the festival_schedule
    if artist in festival_schedule:
        return festival_schedule[artist]
    else:
        return {"message": "Artist not found"}
Fork me on GitHub