Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, please implement the method ridings_recorded and results_for in the class Election: class Election: Data for a single election in a parliamentary democracy. === Private

Hello, please implement the method "ridings_recorded" and "results_for" in the class Election:

class Election: """Data for a single election in a parliamentary democracy.

=== Private Attributes === _d: the date of this election. _ridings: all ridings for which any votes have been recorded in this election. _parties: all parties for which any votes have been recorded in this election. _results: the vote counts for this election. Each key is the name of a riding, and its value is a dictionary of results for that one riding. Each of its keys, in turn, is the name of a party, and the associated value is the number of votes earned by that party in that riding. A party only appears in the dictionary for a riding if that party has had at least one vote recorded in that riding.

=== Representation Invariants == - For all strings s, s in self._ridings iff s in self._results - For all strings s, s in self._parties iff s in self._results[r] for some r - All recorded vote counts are greater than 0. That is, for every key (riding, results) in self._results, for every (party, votes) in results, votes > 0

=== Sample Usage === >>> e = Election(date(2000, 2, 8)) >>> e.update_results('r1', 'ndp', 1234) >>> e.update_results('r1', 'lib', 1345) >>> e.update_results('r1', 'pc', 1456) >>> e.riding_winners('r1') ['pc'] >>> e.update_results('r2', 'pc', 1) >>> e.popular_vote() == {'ndp': 1234, 'lib': 1345, 'pc': 1457} True >>> e.results_for('r1', 'lib') 1345 >>> e.party_seats() == {'ndp': 0, 'lib': 0, 'pc': 2} True """ _d: date _ridings: List[str] _parties: List[str] _results: Dict[str, Dict[str, int]]

def __init__(self, d: date) -> None: """Initialize a new election on date d and with no ridings, parties, or votes recorded so far.

>>> e = Election(date(2000, 2, 8)) >>> e._d datetime.date(2000, 2, 8) """ self._d = d self._ridings = [] self._parties = [] self._results = []

def ridings_recorded(self) -> List[str]: """Return the ridings in which votes have been recorded in this election.

>>> e = Election(date(2000, 2, 8)) >>> e.update_results('r1', 'ndp', 1) >>> e.ridings_recorded() ['r1'] >>> e.update_results('r2', 'ndp', 1) >>> e.ridings_recorded() ['r1', 'r2'] """ # This method

def results_for(self, riding: str, party: str) -> Optional[int]: """Return the number of votes received in by in this election.

Return None if does not have any votes recorded in this election, or if it does, but does not have any votes recorded in this riding in this election.

>>> e = Election(date(2000, 2, 8)) >>> e.update_results('r1', 'ndp', 1234) >>> e.update_results('r1', 'lib', 1345) >>> e.update_results('r1', 'pc', 1456) >>> e.update_results('r2', 'pc', 1) >>> e.results_for('r1', 'pc') 1456 >>> e.results_for('r2', 'pc') 1 """ # This Method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

Students also viewed these Databases questions

Question

2. Write an ad for this position in your new business.

Answered: 1 week ago

Question

8. Providing support during instruction.

Answered: 1 week ago