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
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,...
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr