- 
                Notifications
    
You must be signed in to change notification settings  - Fork 266
 
Ticket Sales
        kyra-ptn edited this page Aug 11, 2024 
        ·
        2 revisions
      
    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?
- A: The problem asks to return the total number of tickets sold from a dictionary that maps ticket types to the number of tickets sold.
 
 - 
Q: What are the inputs?
- A: A dictionary 
ticket_saleswhere keys are ticket types and values are the number of tickets sold. 
 - A: A dictionary 
 - 
Q: What are the outputs?
- A: An integer representing the total number of tickets sold.
 
 - 
Q: Are there any constraints on the values?
- A: The values should be non-negative integers.
 
 
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`.- Ensure that all values in the dictionary are summed correctly.
 - Handle cases where the dictionary might be empty, resulting in a total of 0.
 
def total_sales(ticket_sales):
    total = 0
    for tickets in ticket_sales.values():
        total += tickets
    return total