Question 3: Operators

Liam is organizing a small party. He bought 4 packs of balloons for $3 each, a cake for $20, and 2 packs of party hats for $5 each. He also received a $12 discount on his total purchase. Write a Python program to calculate the total money Liam spent after the discount.

  • Start by asking for Liam’s name and store it in a variable called name.
  • Define variables for the costs:
    • Store the cost per pack of balloons in a variable called balloon_cost and set it to 3.
    • Store the number of balloon packs in a variable called num_balloons and set it to 4.
    • Store the cost of the cake in a variable called cake_cost and set it to 20.
    • Store the cost per pack of party hats in a variable called party_hat_cost and set it to 5.
    • Store the number of party hat packs in a variable called num_party_hats and set it to 2.
    • Store the discount amount in a variable called discount and set it to 12.
  • Calculate the total cost of the balloon packs by multiplying balloon_cost by num_balloons.
  • Calculate the total cost of the party hat packs by multiplying party_hat_cost by num_party_hats.
  • Calculate the total amount before discount by adding the total balloon cost, total party hat cost, and cake_cost.
  • Subtract the discount amount from the total amount before discount to get the final amount spent.
  • Store the final amount in a variable called total_spent.
  • Print a message that includes Liam’s name and the total amount spent after the discount in a friendly sentence, like this: “Hi [name]! After using your discount, you spent a total of $[total_spent] on your party supplies.”
Write what you are looking for, and press enter to begin your search!