Augmented Balance Update

Easy ⏱ 8 min 89% acceptance ★★★★★ 4.9
Write a function apply_transactions(balance, transactions) that starts from balance and applies each amount in the list transactions using augmented assignment (+=), where positive numbers are deposits and negative numbers are withdrawals. Return the final balance.

Examples

Example 1
Input
apply_transactions(100, [50, -30, 20])
Output
140
Explanation

100 + 50 - 30 + 20 = 140.

Example 2
Input
apply_transactions(0, [])
Output
0
Explanation

No transactions leaves the balance unchanged.

Constraints

  • `transactions` is a list of ints or floats, possibly empty.

Topics

Variables & Data Typesaugmented assignment

Companies

PayPalRazorpayDeutsche Bank

Hints

Hint 1

Loop over transactions and do `balance += amount`.

Hint 2

Return balance after the loop finishes.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.