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:
Input this information and compute and output the following statistics:
Below is the complete code as per the requirements. It is well explained inside the code using comments.
# total voters
totalVoters = 0
# under 25 voters
under25 = 0
# number of people from Ward 1 who voted for John Smith
ward1JS = 0
# number of people in Ward 2 who voted
ward2 = 0
# read data until user enter 0
while(True):
print()
voterID = input('Enter the voter ID number [0 to
stop]: ')
# if user enterd 0, stop reading
data
if(voterID == '0'):
break
age = int(input('Age of voter: '))
wardNo = int(input('Ward number [1,2,3,4]:
'))
votedFor = input('Name of person the voter
selected for mayor: ');
# calculate the stats
totalVoters += 1
# if voter under 25
if(age < 25):
under25 +=
1
# if from Ward 1 and voted for John
Smith
if(wardNo == 1 and votedFor == 'John
Smith'):
ward1JS +=
1
# if from ward 2
if(wardNo == 2):
ward2 += 1
# output the satistics
print()
print('Total number of voters:', totalVoters)
print('Number of people under the age of 25 who voted:',
under25)
print('Number of people from Ward 1 who voted for John Smith:',
ward1JS)
print('Number of people in Ward 2 who voted:',ward2)
Below is the screenshot of code in case there is any issue with indentation:
Below is the sample output:
This completes the requirement. Let me know if you have any queries.
Thanks!
Write a Python program to solve the following problem: Information is available about the latest municipal election. For...
Write a program that supports the three phases (setup, voting and result-tallying) which sets up and executes a voting procedure as described above. In more details: You can start with the given skeleton (lab6_skeleton.cpp). There are two structures: Participant structure, which has the following members: id -- an integer variable storing a unique id of the participant (either a candidate or a voter). name -- a Cstring for storing the name of the participant.. hasVoted -- a boolean variable for...
It's Python :D Write a program that does the following: Allow the user to specify the name of an input file containing voter participation data (that way, different data files can be tested). Read the data from the file and write a report out to a new file as follows: The name of the output file should be the name of the input file preceded with the word 'REPORT-'. So, if the input file is named 'PresidentialElections.txt', then the output...
Python code
Write a Python program for each of the following: The following is a social network graph. Each edge (link) in the graph represents a friendship between the involved people. The number on the link represents the number of times the involved people communicated with one another. No number on an edge means 0 communication is happening. You are to write a python program that will store the relations between the people involved in this social network somehow, as...
python question
2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the following information for a stu dent: student number, average quiz mark, average assignment mark, midterm exam mark, and final exam mark (where each mark is recorded out of 100), de termine if the student has passed or failed based on the following information: • A student will pass the course if they have a passing mark (50%...
2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the following information for a stu dent: student number, average quiz mark, average assignment mark, midterm exam mark, and final exam mark (where each mark is recorded out of 100), de termine if the student has passed or failed based on the following information A student will pass the course if they have a passing mark (50% or higher) for...
Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...
Write, test and document a Python program, in a file called MarsCoins.py, to solve the following problem Marvin from Mars has a jar full of martian currency (Maruvians, Caruvians, Taruvians and Paruvians). The breakdown of the currency units on Mars is as follows: The single smallest unit of currency is a Paruvian 6 Paruvians 1 Taruvian 12 Paruvians 1 Caruvian 24 Paruvians1 Maruvian Marvin wants to share his money with his friends but he doesn.t want to carry around all...
Write a program that does the following in Python Code: Stores the following three lists: last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"] first_name =["Lisa", "Bill", "Jay", "Sally", "Walter","Jake","Gary"] phone_number =["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593", "240-671-3221"] Has a function named combine_lists() that takes in last_names, first_names and phone_numbers as lists and returns a dictionary called phone_book that uses last_name as the key and a list consisting of first_name and phone_number. Has a main function that iterates through the...
I HAVE TO SOLVE A C++ PROGRAM, THIS ARE THE INSTRUCTIONS: Write a program that can be used to calculate the federal tax. The tax is calculated as follows: For single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. The tax rates are as follows: If the taxable income is: Between $0 and $15,000, the tax...
Hello, I am trying to solve the following problem using python: Assignment 3: Chatbot A chatbot is a computer program designed to emulate human conversation. For this program you will use if statements, user input, and random numbers to create a basic chatbot. Here is the scenario: You have decided to start an online website. You are creating a prototype to show investors so you can raise money and launch your website. You should ask the user at least 5...