Unit 1 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
service_quality
always be "poor", "average", or "excellent"?
None
in the case of an invalid quality.Plan the solution with appropriate visualizations and pseudocode.
General Idea: Calculate the appropriate tip based on the bill and quality of service.
1) Create a new function with parameters for the bill and service quality
2) Check if the quality matches each possible value
a) If it matches, calculate the tip amount and return it
b) If it doesn't match, check the next possible quality value
3) If no quality matched, return None
def calculate_tip(bill, service_quality):
if service_quality == "poor":
return bill * .1
elif service_quality == "average":
return bill * .15
elif service_quality == "excellent":
return bill * .2
else:
return None