Problem 113068 · easy · Phase 01 Prerequisites & Setup

Cash Rounding

functions · rounding · modulo

Some countries no longer use 1-cent coins, so cash totals are rounded to the nearest 5 cents. Write round_to_step(cents, step) that returns cents rounded to the nearest multiple of step. If cents is exactly halfway between two multiples, round up.

Examples

Input:  cents = 123, step = 5
Output: 125

Input:  cents = 122, step = 5
Output: 120

Input:  cents = 125, step = 10
Output: 130
Explanation: 125 is halfway between 120 and 130, so it rounds up.

Constraints

  • 0 <= cents <= 10**9
  • 1 <= step <= 1000
  • Return an integer.

Goals

  • Round to the nearest multiple of a step
  • Implement a 'ties round up' rule with integer math
Starting Python…