17.6k views
4 votes
The city of Green Acres is holding an election for mayor. City officials have decided to automate the process of tabulating election returns and have hired your company to develop a piece of software to monitor this process. The city is divided into five precincts. On election day, voters go to their assigned precinct and cast their ballots. All votes cast in a precinct are stored in a data file that is transmitted to a central location for tabulation.

Required:
Develop a program to count the incoming votes at election central.

1 Answer

6 votes

Answer:

Step-by-step explanation:

The following program asks the user to enter the precinct number and then loops to add votes until no more votes need to be added. Then it breaks the loop and creates a file called results to save all of the results for that precinct.

precinct = input("Enter Precinct Number: ")

option1 = 0

option2 = 0

while True:

choice = input("Enter your vote 1 or 2: ")

if int(choice) == 1:

option1 += 1

else:

option2 += 1

endVote = input("Vote again y/n")

if endVote.lower() != 'y':

break

f = open("results.txt", "w")

f.write("Precinct " + precinct + ": \\Option 1: " + str(option1) + "\\Option 2: " + str(option2))

The city of Green Acres is holding an election for mayor. City officials have decided-example-1
User MrGray
by
4.2k points