Moving the rounding boundary

A store applies a 10% discount to item prices recorded as nonnegative integer cents. A developer proposes the following Python change as a refactoring:


Python
def original_total(prices):
    return sum((price * 9) // 10 for price in prices)


def proposed_total(prices):
    return (sum(prices) * 9) // 10


For these nonnegative values, // 10 divides by ten and discards any fractional part. Fill in both functions' returned totals for each basket. Enter exact integers in cents; do not apply any additional rounding.

Item prices in centsOriginal total in centsProposed total in cents
11, 11
20, 30
13, 13, 13

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Refactoring Questions: