Answer to Question #293759 in Python for Jaber123

Question #293759

A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time.

Write an application that calculates and displays the parking charges for each customer who parked in the garage yesterday. You should enter the hours parked for each customer.

The program should display the charge for the current customer and should calculate and display the running total of yesterday’s receipts. The program should use the method calculateCharges() to determine the charge for each customer.


1
Expert's answer
2022-02-03T16:35:07-0500
import datetime
from datetime import timedelta
from datetime import datetime


def calculateHours(hours, minutes):
    yesterday = datetime.now() - timedelta(1)
    then = datetime(yesterday.year, yesterday.month, yesterday.day, hours,
                    minutes)
    now = datetime.now()
    duration = now - then
    if duration.total_seconds() % 3600 == 0:
        duration_in_h = duration.total_seconds() // 3600
        return duration_in_h
    else:
        duration_in_h = duration.total_seconds() // 3600 + 1
        return duration_in_h


def calculateCharges(duration_in_h):
    if duration_in_h <= 3:
        return 2
    else:
        pay = 0.5 * (duration_in_h - 3) + 2
    if pay > 10:
        return 10
    else:
        return pay


def main():
    hours = int(input('Enter hours: '))
    minutes = int(input('Enter minutes: '))
    duration_in_h = calculateHours(hours, minutes)
    print(calculateCharges(duration_in_h))


if __name__ == '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS