1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Python for Finance

Connected

Exercise

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.

Instructions 1/3

undefined XP
  • 1
    • Assign the number of sales to the variable num_sales.
    • Check if the number of purchases is less than the number of sales.
  • 2
    • Write a control statement to check if there were fewer sales than purchases.
  • 3
    • Check if both sales and purchases are empty.