Write a Python program to solve the following problem: Information is available
ID: 3892135 • Letter: W
Question
Write a Python program to solve the following problem: Information is available about the latest municipal election. For each voter, the following data is given: . voter id number . age of voter the ward number (1, 2, 3 or 4) in which the voter resides the name of the person the voter selected for mayor Input this information and compute and output the following statistics: the total number of people who voted the number of people between age 30 and 50, inclusive, who voted for John Smith the number of people from Ward 2 who voted the number of people who did not vote for John SmithExplanation / Answer
ScreenShot
--------------------------------------------------------------
Program
#This is a program to check different criterial statistics of a Mayor election
#Use four different functions to collect statistic details
#count the total number of voters
def countTotalNoPeople(vId):
return len(vId)
#count the voters between 30-50 and mayor=John Smith
def countAgeTotal(vAge,vName):
count=0
for i in vAge:
if i>"30" and i<"50":
indx=vAge.index(i)
print(indx)
if vName[indx]=='John Smith':
count=count+1
return count
#Count number of voters in ward 2
def countWard2(vNo):
count=0
for i in vNo:
if i==2:
count=count+1
return count
#Number of voters not voted for John Smith
def notJohnSmith(vName):
count=0
for i in vName:
if i!="John Smith":
count=count+1
return count
#Main method
def main():
#Details storing list
vId=[]
vAge=[]
vNo=[]
vName=[]
#Check the voting processing or not
response=int(input("If you are a voter enter 1 else enter 0:"))
#Take voting details and storing corresponding list
while response==1:
voterId=input("Enter Voter Id:")
while len(voterId)!=15:
print("ID must be 15 digits.Please verify!!")
voterId=input("Enter Voter Id:")
vId.append(voterId)
vAge.append(input("Please enter age:"))
wardNo=int(input("Please enter the Ward No:"))
while wardNo<0 or wardNo>4:
print("Ward number always within 1-4.Please check!!!")
wardNo=input("Please enter the Ward No:")
vNo.append(wardNo)
vName.append(input("Please enter the name of the Mayor do you like:"))
response=int(input("If you are a voter enter 1 else enter 0:"))
#Call each function to get statistical details
totalNoPeople=countTotalNoPeople(vId)
ageTotal=countAgeTotal(vAge,vName)
ward2Count=countWard2(vNo)
noVoteCount=notJohnSmith(vName)
#Display statistics
print(" Mayor Vote Statistics ")
print()
print("Count of total votes Count Of votes for John Smith(between 30-50 age) Vote count of ward2 Count of votes not for John Smith")
print(" ",totalNoPeople," ",ageTotal," ",ward2Count," ",noVoteCount)
if __name__== "__main__":
main()
-------------------------------------------------
Output
If you are a voter enter 1 else enter 0:1
Enter Voter Id:123456789458796
Please enter age:31
Please enter the Ward No:2
Please enter the name of the Mayor do you like:John Smith
If you are a voter enter 1 else enter 0:1
Enter Voter Id:456789123478296
Please enter age:40
Please enter the Ward No:3
Please enter the name of the Mayor do you like:Hillary Blake
If you are a voter enter 1 else enter 0:0
0
1
Mayor Vote Statistics
Count of total votes Count Of votes for John Smith(between 30-50 age) Vote count of ward2 Count of votes not for John Smith
2 1 1 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.