232. Python Program to Calculate a Parking Fee by Hours
EasyPhase 1 · Warm-up
This one uses input(), int() and if. You know all three.
Overview
Car parks charge by the hour, and most of them have a daily cap. A cap is the most you can pay: after it, extra hours are free.
Problem Statement
Lucía runs a small car park. The prices are:
- 0 hours (the car leaves at once) is free: 0 coins.
- The first hour costs 20 coins.
- Each extra hour after the first costs 10 coins.
- The daily cap is 100 coins. No one pays more than 100 coins for one day.
Read the number of hours a car was parked. Print the fee as Fee: <fee> coins.
Steps
- Read the hours and turn them into a whole number.
- If the hours are 0, the fee is 0.
- Else, the fee is 20 coins for the first hour plus 10 coins for each of the other hours.
- If that fee is more than 100, make it 100.
- Print the fee.
Examples
Example 1. Input 3 gives:
Fee: 40 coins
Why: the first hour is 20 coins, and the 2 extra hours are 2 × 10 = 20 coins. 20 + 20 = 40.
Example 2. Input 12 gives:
Fee: 100 coins
Why: without the cap the fee would be 20 + 11 × 10 = 130 coins. That is more than 100, so the cap makes it 100.
Input
One whole number: the hours the car was parked, from 0 to 24. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
One line: Fee: <fee> coins. The tests try 6 different inputs, also 0, 1 and 9.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.