Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Q: What is the problem asking for?
Q: What are the inputs?
artist
and a dictionary festival_schedule
mapping artist's names to their schedule details (day, time, stage).Q: What are the outputs?
Q: What should be returned if the artist is not in the schedule?
{"message": "Artist not found"}
.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
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"}