DAY 03 OF 100 · Rounding · tiered pricing

Medium

A Parking Meter With Boundaries.

Today’s challenge

Build the solution

Write a function called parking_bill(minutes) for a parking garage.

Return contract: A dictionary with integer blocks and total_cents.

Input bounds: minutes is an integer from 0 to 10,000.

Keep the supplied driver below your implementation. It reads one JSON object and prints your return value as JSON. The driver may also probe the behaviour described above; those probe fields are part of the test input.

  1. The first 15 minutes are free. After that, every started 30-minute block is charged.
  2. The first four charged blocks cost 200 cents each. Each additional block costs 150 cents.
  3. Cap the amount due at 1,800 cents. Report the actual charged block count even when the cap applies.

The Twist: A stay of 45 minutes has one charged block; 46 minutes has two. Do not use floating-point rounding.

Sample

Input

{"minutes":46}

Expected output

{"blocks":2,"total_cents":400}
day-3.py
Python 3
Tab inserts four spaces. Press Escape, then Tab to move to the next control, or Shift+Tab to move to the previous control.

Log in or create an account to run code, submit solutions, and save your progress.

Output

Run your code to see the result here.