- scratchpad.py
- Unit Test
Test Cases
x/x
Pass | Test | Message | |
---|---|---|---|
- | Test results will show here. | - |
Errors:
Problem Statement
You are a high school prom coordinator who needs to keep track of students’ votes for the Prom King and Queen. Given a list of dictionaries where each dictionary represents a student’s vote, you need to calculate the total votes for each candidate and determine the candidates with the highest votes.
Instructions
Write a function calculate_prom_votes(votes)
that takes a list of dictionaries (votes
) as an argument. Each dictionary contains the following keys and values:
- ‘king’: The name of the student voted for Prom King (string).
- ‘queen’: The name of the student voted for Prom Queen (string).
Your function should return a tuple containing two elements:
- A dictionary with the total votes for each candidate, where the keys are the candidates’ names and the values are their total votes. This dictionary should have two nested dictionaries, one for ‘king’ and one for ‘queen’.
- A tuple with the names of the students with the highest votes for Prom King and Prom Queen.
If there are no votes provided, the function should return two empty dictionaries and None for both the Prom King and Prom Queen.
Example
Input: [{'king': 'Sam', 'queen': 'Nina'}, {'king': 'Sam', 'queen': 'Nina'}, {'king': 'Alex', 'queen': 'Maya'}]
Expected result: ({'king': {'Sam': 2, 'Alex': 1}, 'queen': {'Nina': 2, 'Maya': 1}}, ('Sam', 'Nina'))
Upload an image
Upload from your computer
Or paste a link here
Slides and Notes
No slides available for this video
About
Python 3 Practice
3.11.9 (default, Apr 6 2024, 17:59:24)
[GCC 6.4.0]