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...
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'))
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
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...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
Writing a Modular Program in Python In this lab, you add the input and output statements...
Writing a Modular Program in Python In this lab, you add the input and output statements to a partially completed Python program. When completed, the user should be able to enter a year, a month, and a day. The program then determines if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31. Instructions Notice that variables have been declared...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT