Aan de slagGa gratis aan de slag

Branching with elif and else

elif and else statements let you extend your code to handle cases not handled by your initial control statement. In this exercise you will sort security transactions based on their stock symbol. You might do this to better understand how some popular stocks are bought and sold. You are provided with the variable trn which holds the transaction, and the empty lists appl, tsla, and amzn to hold sorted transactions.

Deze oefening maakt deel uit van de cursus

Intermediate Python for Finance

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Get the symbol value
symbol = trn['symbol']

# Check if Apple stock
____ symbol ____ 'APPL'____
    appl.append(trn)
Code bewerken en uitvoeren