Status: Not Started
  • scratchpad.py
  • Unit Test
Font Size
14
Parentheses autocomplete
Wrap lines
Editor
Theme
Code with blocks by default
Console Font Size
12
Console Theme
Display Server Graphics Screen
Show File Tab Bar
Debug Mode
Prom King and Queen
Unit Test
def calculate_prom_votes(votes):
return
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output
Grading
Docs
Exercise
More
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Pass Test Message

Errors:

This student is viewing this assignment in English. View this page in English?

5 points

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:

  1. 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’.
  2. 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'))

Reset Code

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]