LoslegenKostenlos loslegen

Breaking out of a for loop

You can use loops to perform operations which change depending on the data. For this exercise, you given a list of purchase transactions in the variable buys. You need to calculate the final balance of your client's account after the purchases have been made, but you do not want the account to have a negative balance. The initial account balance is provided in the variable balance.

Diese Übung ist Teil des Kurses

Intermediate Python for Finance

Kurs anzeigen

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Loop through buys
____ buy ____ buys:
    print('Buying ' + buy['symbol'])
    new_balance = ____ - buy['total_cost']
    balance = new_balance

print(balance)
Code bearbeiten und ausführen