Question: Write a Program in Python ( functional programming (use several functions) and while true for validation) to calculate the parking fare for customers who park

Write a Program in Python ( functional programming (use several functions) and while true for validation) to calculate the parking fare for customers who park their cars in a parking lot when the following information is given: a) A string showing the type of vehicle: car, bus and truck b) An integer between 0 and 24 showing the hour the vehicle entered the lot c) An integer between 0 and 60 showing the minute the vehicle entered the lot d) An integer between 0 and 24 showing the hour the vehicle left the lot e) An integer between 0 and 60 showing the minute the vehicle left the lot This is a public lot. To encourage people to park for a short period of time, the management uses two different rates for each type of vehicle, as shown below: Vehicle First Rate Second Rate Car $0.00/hr first 3 hours $1.50/hr after 3 hours Truck $1.00/hr first 2 hours $2.30/hr after 2 hours Bus $2.00/hr first 1 hour $3.70/hr after 1 hour You can assume that all vehicles will not be in the parking lot any later than midnight. The input data consist of a string and a set of four integers representing the type of vehicle and the entering and leaving hours and minutes. But these pieces of data must be input into the computer in a user-friendly way. In other words, the computer must prompt the user to enter the data like shown below: Type of vehicle? Car Hour vehicle entered lot (0 24)? 14 Minute vehicle entered lot (0 60)? 23 Hour vehicle left lot (0 24)? 18 Minute vehicle left lot (0 60)? 8 The output format is shown below:

PARKING LOT CHARGES

Type of vehicle: Car TIME-IN XX : XX

TIME-OUT XX : XX

PARKING TIME XX : XX

ROUNDED TOTAL XX

TOTAL CHARGES $XX.XX

This program must first calculate the actual time spent in the parking lot for each vehicle. This means using modulo arithmetic to handle time calculations. There are many ways to handle this and one way is shown below: 1. Compare the minute portion of the leaving and entering time If the first one is smaller than the second Add 60 to the minute portion of the leaving time Subtract 1 from the hour portion of the leaving time 2. Subtract the hour portion 3. Subtract the minute portion 4. Since there are no factional hour charges, the program must also round the parking time up to the next hour before calculating the charge. Criteria to include: 1. Functions are to be used appropriately. 2. Your program should continually run and re-display the main menu until the user decides to exit. 3. You may include any other additional features into your program based on your creativity. 4. Test Data using while true

please do not copy the following answer (code) which is the simplest way but as i mentioned i need to use several functions( one function for vehicle type, a functions for vehicle Entry Hour, one function for vehicle Entry Minute, one function for vehicle Exit Hour and one for vehicle Exit Minute), please write global and local loop and while true for validation. I asked this question several time but unfortunately nobody pay attention to my request which is using several function and while true for validation.

Program for Parking Lot

def ParkingCharge(vehicle,P_hour): #Function to calculate Parking Charges charge=0 if(vehicle=="car"): # when vehicle is car if(P_hour>3): charge=1.50*P_hour elif(vehicle=="truck"): # when vehicle is truck if(P_hour<=2): charge=P_hour*1.00 else: charge=P_hour*2.30 elif(vehicle=="bus"): # when vehicle is bus if(P_hour==1): charge=P_hour*2.00 else: charge=P_hour*3.70 return charge #returning charges

if __name__ == "__main__": #main body exitMenu="1" #for checking exit status while(exitMenu!="0"): #loop re-display the main menu until the user decides to exit vehicle=input("Type of vehicle(Car, Bus, Truck): ").lower() #taking input and converting to lower case inHour=int(input("Hour vehicle entered lot(0-24): ")) inMin=int(input("Minute vehicle entered lot(0-60): ")) outHour=int(input("Hour vehicle left lot(0-24): ")) outMin=int(input("Minute vehicle left lot(0-60): "))

TotalInTime= inHour*60 + inMin #converting total in time to minutes TotalOutTime= outHour*60 + outMin #converting out time to minutes ParkingTime= TotalOutTime- TotalInTime #calculating parking time Parking_Hour= ParkingTime//60 # calculating parking hour Parking_Min=ParkingTime%60 #calculating parking minute Total_p=Parking_Hour #rounded time if(Parking_Min>0): Total_p=Parking_Hour+1 #rounded time P_charge=ParkingCharge(vehicle,Parking_Hour) #calling function to calculate parking charge if(vehicle not in ['car','bus','truck']): #checking invalid vehicle print(" VEHICLE NOT RECOGNIZED") else: #if the vehicle is valid print("---PARKING LOT CHARGES---") #printing output print("Type of vehicle= ",vehicle) print("TIME-IN= {}:{}".format(inHour,inMin)) #using string formatting for proper output print("TIME-OUT= {}:{}".format(outHour,outMin)) print("PARKING TIME= {}:{}".format(Parking_Hour,Parking_Min)) print("ROUNDED TOTAL=",Total_p) print("TOTAL CHARGES={:.2f}".format(P_charge)) #formatting to 2 decimal place exitMenu=input(" Press 0 and hit enter to exit any other key to continue: ") #asking user to exit or not

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!