This Python program calculates the parking fee based on the customer's usage time.
The rules are simple:
- A flat rate of $10 applies for any duration up to 24 hours
- No vehicle stays longer than 24 hours
- The user enters hours and minutes, and the system calculates and displays the fee
def calculate_parking_fee(hours: int, minutes: int) -> float:
total_minutes = hours * 60 + minutes
if total_minutes > 0 and total_minutes <= 24 * 60:
return 10.0
else:
raise ValueError("Invalid duration: must be between 0 and 24 hours.")
# Run the program
hours = int(input("Enter hours parked: "))
minutes = int(input("Enter minutes parked: "))
try:
fee = calculate_parking_fee(hours, minutes)
print(f"Total parking fee: ${fee:.2f}")
except ValueError as e:
print(f"Error: {e}")
Total parking fee: $10.00
- The user enters the number of hours and minutes parked
- The program converts the total time to minutes
- If the total is within 0 to 1440 minutes (24 hours), the fee is $10
- Otherwise, an error is raised
- The result is displayed with two decimal places