python 3.x - Program to calculate the number of votes towards a political party, and then arrange them in alphabetical order -
There is a small problem with a program I am currently working in. In this program, I am using a political party / I encourage them to enter the names of whom they want to vote for. After this I calculate the number of votes for each party and then according to the names of political parties, arrange the number of votes for the party / parties in alphabetical order. Here's my program:
print ("Independent Election Commission \ n --------------------------- ----- ") Vote = [] # Vote = input (" Enter the names of parties that have been terminated "), to vote for the political party / parties to vote for the user: \ n" )! = 'Full': Vote. Appendix (vote) # votes = Input ("") Counter = {} Adds votes to the user / type of votes to vote # This is definitely the total number of votes Counting of votes: Political parties to vote for votes: If there are no votes in the counters: [Vote] = 0 Counter [Vote] + = 1 Print ("\ n" "Number of votes: "): Print (vote + '' * * (10 - lane (vote)), '-', counter [vote]) I see the output is:
Independent Election Commission -------------------------------- Enter the names of parties (Completed Ended): DAL ACO OPT Pulses DAL PRQ DAL Voting Calculations: A IO - 1 DAL - 4 OPT - 1 PRQ-1 - Instead I get this: Independent Election Committee n ---------------- ---------------- Enter the names of the parties (Completed ends): DAL ACOO OPT Pill DAL PRQ DAL Vote count: PRQ - 1 DAL - 4 ACNO - 1 OPT - 1
sorted_parties = sorted (counters .keys ()) Then, after calculating the total number of votes for the print, just sort the key it is in the sorted parties To vote: Print (votes + '* (10 - Lane (vote)),' - ', counter [vote])
Comments
Post a Comment