Get startedGet started for free

Comparing sales and purchases

If statements let you branch your code to take different actions depending on the state of your data. Imagine you are working at a small firm trying to keep the number items sold in balance with those purchased. You are supplied with two lists, purchases, which contains items purchased, and sales, which contains items sold. Use if statements to compare the two lists.

This exercise is part of the course

Intermediate Python for Finance

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Get number of purchases
num_purchases = len(purchases)
# Get number of sales
num_sales = ____(sales)

# Check if more sales than purchases
____ num_purchases < num_sales:
    print('buy more')
Edit and Run Code