The following function is intended to take a list of strings as an argument (with each element representing a vote for the candidate of that name), and output the winner of the election in the form of def majorvote(votes): vote_count = 0; candidate = votes[i] the name of the candidate who received more than half of the votes, vote_count += 1 or 'no-one' if there was no outright winner. maxvotes = 0 For example: if votes[j] == candidate: >>> majorvote(['alice', 'bob', 'alice', 'carol', 'alice 'alice' else: >>> majorvote(['alice', 'alice', 'carol', 'bob', 'eric' 'no-one' maxvotes = vote_count; winner = candidate >> majorvote(['alice']) 'alice' for j in range(len(votes)): In the first case, the output is 'alice' as they received three votes if vote_count > maxvotes: out of the total of five (i.e. more than half the votes), but in the if maxvotes > len(votes)/2: second cate, the output is 'no-one', as no candidate receives three or more (out of the total of five) votes. return 'no-one' AIl the roguired lines of the function are available ouut of order in

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 8PE: Write a program that reads in a line consisting of a students name, Social Security number, user ID,...
icon
Related questions
Question
The following function is intended to take a list of strings as an
argument (with each element representing a vote for the candidate
of that name), and output the winner of the election in the form of
the name of the candidate who received more than half of the votes,
def majorvote(votes):
vote_count
0; candidate = votes[i]
%3D
vote_count += 1
or 'no-one' if there was no outright winner.
maxvotes = 0
For example:
if votes [j] == candidate:
>>> majorvote(['alice', 'bob', 'alice', 'carol', 'alice
'alice'
else:
>>> majorvote(['alice', 'alice', 'carol', 'bob', 'eric'
'no-one'
maxvotes = vote_count; winner = candidate
>>> majorvote(['alice'])
'alice'
for j in range (len(votes)):
In the first case, the output is 'alice' as they received three votes
if vote_count > maxvotes:
out of the total of five (i.e. more than half the votes), but in the
second cate, the output is 'no-one', as no candidate receives three
or more (out of the total of five) votes.
if maxvotes > len(votes)/2:
return 'no-one'
All the required lines of the function are available, out of order, in
for i in range (len(votes)):
the editor panel. Drag each line across to the solution area to the
right, put them in the correct order, and introduce appropriate
return winner
indentation.
Transcribed Image Text:The following function is intended to take a list of strings as an argument (with each element representing a vote for the candidate of that name), and output the winner of the election in the form of the name of the candidate who received more than half of the votes, def majorvote(votes): vote_count 0; candidate = votes[i] %3D vote_count += 1 or 'no-one' if there was no outright winner. maxvotes = 0 For example: if votes [j] == candidate: >>> majorvote(['alice', 'bob', 'alice', 'carol', 'alice 'alice' else: >>> majorvote(['alice', 'alice', 'carol', 'bob', 'eric' 'no-one' maxvotes = vote_count; winner = candidate >>> majorvote(['alice']) 'alice' for j in range (len(votes)): In the first case, the output is 'alice' as they received three votes if vote_count > maxvotes: out of the total of five (i.e. more than half the votes), but in the second cate, the output is 'no-one', as no candidate receives three or more (out of the total of five) votes. if maxvotes > len(votes)/2: return 'no-one' All the required lines of the function are available, out of order, in for i in range (len(votes)): the editor panel. Drag each line across to the solution area to the right, put them in the correct order, and introduce appropriate return winner indentation.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr