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?
ticket_sales
where keys are ticket types and values are the number of tickets sold.Q: What are the outputs?
Q: Are there any constraints on the values?
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Sum up all the values in the ticket_sales
dictionary to get the total number of tickets sold.
1) Initialize a variable `total` to 0.
2) Iterate through all the values in the `ticket_sales` dictionary.
- For each value, add it to `total`.
3) Return the value of `total`.
⚠️ Common Mistakes
def total_sales(ticket_sales):
total = 0
for tickets in ticket_sales.values():
total += tickets
return total