Question

In python Please The general elections are over, now is the time to count the votes...

In python Please


The general elections are over, now is the time to count the votes and find out who will take the reins of this country. There are c (2 <= c <= 6) candidates and m (1 <= m <= 74) voting regions. Given the number of votes for each candidate in each municipality, determine which candidate is the winner (the one with the most votes). Input Format The first line of input contains an integer T (1 <= T <= 100), the number of test cases that follow. Each test case begins with two integers c and m that denote the number of candidates and regions respectively. The next m lines each contain n integers V1, V2, ..., Vn (0 <= Vi <= 1000) the number of votes for candidate c. Constraints c (2 <= c <= 6) candidates m (1 <= m <= 74) (0 <= Vi <= 1000) the number of votes for candidate c Output Format For each test case, print the winning candidate on one line. You can assume that the winner is unique.

Homework Answers

Answer #1

Here is th python code:

NOTE: Here is the python code, when you run to update the filename = 'candidatesList.txt' with the correct filename which contains the test cases

def main():
try:
filename = 'candidatesList.txt'
f = open(filename, 'r')
test_cases = int(f.readline().strip())
for test in range(test_cases):
cand_region = f.readline().strip().split()
candidatesList, regions = int(cand_region[0]), int(cand_region[1])

candidate_votes = [0] * candidatesList
for region in range(regions):
vote_line = f.readline().strip().split()
votes = [int(v) for v in vote_line]
for i in range(candidatesList):
candidate_votes[i] += votes[i]

winner_candidate = candidate_votes.index(max(candidate_votes)) + 1
print(winner_candidate)
except:
print('Error: File: {} not found.'.format(filename))

main()

#********I hope you find this helpful and please do UPVOTE as to appreciate my effort..THANKS:)******

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Take Three Jojo just graduated and moved up to grade 4. Today is his first day...
Take Three Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. After the 4th graders finished their first task which is prime factorization. Jojo’s teacher set up a game for the stundets. The game is very simple. Given N colored balls, each student has to take...
Death Battle Problem Description In a crossover fantasy universe, Houin Kyoma is up in a battle...
Death Battle Problem Description In a crossover fantasy universe, Houin Kyoma is up in a battle against a powerful monster Nomu that can kill him in a single blow. However being a brilliant scientist Kyoma found a way to pause time for exactly M seconds. Each second, Kyoma attacks Nomu with certain power, which will reduce his health points by that exact power. Initially Nomu has H Health Points. Nomu dies when his Health Points reach 0. Normally Kyoma performs...
Acme Super Store is having a contest to give away shopping sprees to lucky families. If...
Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example, one family member can take one television, one watch and one toaster, while another family member can take one television, one camera and one pair...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT