HackLand Election In elections that use the ballot box system for voting, each voter writes the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
HackLand Election In elections that use the ballot box system for voting, each voter writes the name of a candidate on a ballot and places it in the ballot box. The candidate with the highest number of votes wins the election. If two or more candidates have the same number of votes, then the tied candidates' names are ordered alphabetically and the last name in the alphabetical order wins. For example, votes are in the names [Joe', 'Mary', 'Mary', 'Joe']. Each candidate received two votes, but Mary is alphabetically later than Joe, so she wins. Function Description Complete the function election Winner in the editor below. The function must return a string denoting the name of the winning candidate. election Winner has the following parameter(s): votes[votes[0],...votes[n-1]]: an array of strings representing the names of the candidates as voted by the voter. Constraints • 1 ≤ns 104 ▼ Input Format For Custom Testing Input from stdin will be processed as follows and passed to the function: The first line contains an integer n, the number of elements in votes. Each the n subsequent lines contains a string describing votes[i] where 0 <i<n. ▾ Sample Case 0 Sample Input 0 10 Alex Michael Harry Dave Michael Victor Harry Alex Mary Mary Sample Output 0 Michael Explanation 0 The votes tally is: • 2 votes: Alex, Harry, Michael, Mary • 1 vote: Dave, Victor The highest vote count is 2, and among those receiving 2 votes, the last name alphabetically is Michael 1#!/bin/python3. 10 11 # Complete the electionWinner function below. 12 def electionWinner (votes): 13 14 if name main HackLand Election In elections that use the ballot box system for voting, each voter writes the name of a candidate on a ballot and places it in the ballot box. The candidate with the highest number of votes wins the election. If two or more candidates have the same number of votes, then the tied candidates' names are ordered alphabetically and the last name in the alphabetical order wins. For example, votes are in the names [Joe', 'Mary', 'Mary', 'Joe']. Each candidate received two votes, but Mary is alphabetically later than Joe, so she wins. Function Description Complete the function election Winner in the editor below. The function must return a string denoting the name of the winning candidate. election Winner has the following parameter(s): votes[votes[0],...votes[n-1]]: an array of strings representing the names of the candidates as voted by the voter. Constraints • 1 ≤ns 104 ▼ Input Format For Custom Testing Input from stdin will be processed as follows and passed to the function: The first line contains an integer n, the number of elements in votes. Each the n subsequent lines contains a string describing votes[i] where 0 <i<n. ▾ Sample Case 0 Sample Input 0 10 Alex Michael Harry Dave Michael Victor Harry Alex Mary Mary Sample Output 0 Michael Explanation 0 The votes tally is: • 2 votes: Alex, Harry, Michael, Mary • 1 vote: Dave, Victor The highest vote count is 2, and among those receiving 2 votes, the last name alphabetically is Michael 1#!/bin/python3. 10 11 # Complete the electionWinner function below. 12 def electionWinner (votes): 13 14 if name main
Expert Answer:
Answer rating: 100% (QA)
Python version 36 Python program to create and test function electionWinner def electionWinnervotes ... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
A common task that must be done in a loop is to find the maximum and minimum of a sequence of values. The file Temps.java contains a program that reads in a sequence of hourly temperature readings...
-
Any work required in an Appendix must be done in the blue boxes. Please read the narrative carefully to see what Elliot is requesting. 5 Appendix I Production in units: 8 Terrific Tank 9 Run Like the...
-
In Problem 19.13, what could be done to? (a) Increase the production rate and/or (b) Reduce the operating costs of the cell in light of your analysis? Support your answers with calculations. Problem...
-
Phoenix Corp. faltered in the recent recession but is recovering. Free cash flow has grown rapidly. Forecasts made in 2016 are as follows. Phoenix's recovery will be complete by 2021, and there will...
-
A company like Golf USA that sells golf-related inventory typically will have inventory items such as golf clothing and golf equipment. As technology advances the design and performance of the next...
-
Sutton Pointers Corporation expects to begin operations on January 1, 2015; it will operate as a specialty sales company that sells laser pointers over the Internet. Sutton expects sales in January...
-
Explain several implications of IFRS on financial reporting by health care organizations.
-
BusServ.com Corporation provides business-to-business services on the Internet. Data concerning the most recent year appear below: Sales . . . . . . . . . . . . . . . . . . . . . . . $8,000,000 Net...
-
How can we add Database connection script to search product item form input into MySQL Database Tables?
-
Charles Whyte commenced business on May 1 2019, making up his accounts to September 30 annually. The statement of the Profit or Loss Account for the first 17 months ended September 30,2020 is as...
-
On one k-y graph, show the economy a) in the original equilibrium in year zero, b) in the original equilibrium in year ten. c) in year three d) in the new equilibrium in year ten, with reduced g but...
-
Objective: Using the provided code (Box.java and Question03.java), write methods that returns the instances of boxes that have the minimum and maximum weight of an array of boxes. Requirements: ...
-
Consider the following two C++ programs P and P2 and two statements S and S2 about the programs: P1 P2 double a = 1, b void f(int a, int*b, =2; int &c) double &f(double { a = 1; &d) *b=2; c = 3; d =...
-
refactor this code? package edu.gatech.seclass.edtext; import org.apache.commons.cli.*; import org.apache.commons.lang3.StringUtils; import java.io.FileNotFoundException; import java.io.IOException;...
-
Janet is planning to visit Arizona, New Mexico, and California on a 14-day vacation. If she plans to spend as much time in New Mexico as she does in the other two states combined, how can she allot...
-
RefactoreState pattern in Control (using Enums for the various Menus, Forms) So. NO USE of the Builders at all. What I tried to do was take the code from toUIMenu() out of the menu builder and put it...
-
11 Let A - [24]. = (a) Find all eigenvalues and corresponding eigenvectors of A. (b) Find an invertible matrix P such that P-AP is a diagonal matrix. (c) Compute. A 30 Let the linear transformation...
-
Controls can be identified based on their function. The functions are preventive, detective, and corrective. A. True B. False
-
Public Schools and Private School Vouchers: Consider a simple model of how economic circumstances are changed when the government enters the education market. A: Suppose a household has an after-tax...
-
Consider your tastes for five dollar bills and ten dollar bills (and suppose that you could have partial $10 and $5 bills). A: Suppose that all you care about is how much money you have, but you dont...
-
Public School Teacher Salaries, Class Size and Private School Markets: In exercise 14.10, we noted that private schools that charge tuition operate alongside public schools in U.S. cities. There is...
-
Construct a stem-and-leaf plot of the poverty data discussed in Example 6. Approach We will use Minitab. The steps for constructing the graphs using Minitab or StatCrunch are given in the Technology...
-
Draw a dot plot for the number of arrivals at Wendys data from Table 8. Approach The smallest observation in the data set is 1 and the largest is 11. Write the numbers 1 through 11 horizontally. For...
-
The following data represent the number of grams of fat in breakfast meals offered at a local fast food restaurant. (a) construct a stem-and-leaf plot and (b) describe the shape of the distribution....
Study smarter with the SolutionInn App