Question

In: Computer Science

make a python program which forms caravan occupancy report the output should be in a table...

make a python program which forms caravan occupancy report

the output should be in a table format which shows the occupants, number of caravans and the percentage.

caravans with over 9 occupants are considered to be over crowded, and are to be output under a single column (>9).

Solutions

Expert Solution

Program:

from prettytable import PrettyTable
caravan = [] #list for holding number of occupants
overcrowded = [] #list for holding overcrowded information
no_of_occupants=0
no_of_caravan = input("Enter number of caravan:") #get number of caravan
#for every caravan run the loop
for x in range(no_of_caravan):
occupants = input("Enter occupants") #get number of occupants as input
caravan.append(occupants)
if occupants> 9: #if occupants are above 9, mark as overcrowded
overcrowded.append("Yes")
else:
overcrowded.append("No")
no_of_occupants=occupants+no_of_occupants #add occupants to find total occupants
percentage = (no_of_occupants/(no_of_caravan*9)*100) #calculate percentage

#display output in table format using PrettyTable module
t = PrettyTable(['Occupants', 'Number of caravan', 'Percentage', 'Overcrowded'])
#for every caravan run the loop
for x in range(no_of_caravan):
t.add_row([caravan ,no_of_caravan, percentage , overcrowded]) #add row
print(t) #print the table

Explanation:

i) The program uses prettytable module to get output in table format.

ii) The program gets number of caravan from the user and runs the loop for no_of_caravan times.

iii) It gets the number of occupant and calculate total occupants and percentage ( no_of_occupants/(no_of_caravan*9)*100 ).

iv) The program uses for loop of no_of_caravan times executable to add rows to the table .

v) The expected output is achieved


Related Solutions

Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
Write a Python program which adds up columns and rows of given table as shown in...
Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.): Input number of rows/columns (0 to exit) 4 Input cell value: 25 69 51 26 68 35 29 54 54 57 45 63 61 68 47 59 Result:             25   69   51   26 171...
Write a Python program which adds up columns and rows of given table as shown in...
Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.): Input number of rows/columns (0 to exit) 4 Input cell value: 25 69 51 26 68 35 29 54 54 57 45 63 61 68 47 59 Result: 25 69 51 26 171 68 35...
I need to write a program in python for a restaurant. The program should let the...
I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong. print ("Welcome...
Make a calculator in python that always gives an explanation when the answer is output. It...
Make a calculator in python that always gives an explanation when the answer is output. It must be detailed
In Python Find the errors, debug the program, and then execute to show the output. def...
In Python Find the errors, debug the program, and then execute to show the output. def main():     Calories1 = input( "How many calories are in the first food?")     Calories2 = input( "How many calories are in the first food?")     showCalories(calories1, calories2)    def showCalories():     print('The total calories you ate today', format(calories1 + calories2,'.2f'))
Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has.
Use JAVAProgram #1: Hotel Occupancy: Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how...
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT