Question 7: Operators

Mary bought a dog and a toy bone for her dog. She spent $150 on the dog and $20 on the toy bone. Later, she sold her dog for $300. Write a Python program to calculate how much money Mary made from selling her dog.

  • Start by asking for Mary’s name and store it in a variable called name.
  • Define variables for the costs:
    • Store the cost of the dog in a variable called cost_of_dog and set it to 150.
    • Store the cost of the toy bone in a variable called cost_of_toy_bone and set it to 20.
    • Store the selling price of the dog in a variable called selling_price_of_dog and set it to 300.
  • Calculate the total amount Mary spent by adding the cost of the dog and the cost of the toy bone.
  • Calculate the profit by subtracting the total amount spent from the selling price of the dog.
  • Store the profit in a variable called profit.
  • Print a message that includes Mary’s name and the profit in a friendly sentence, like this: “Hi [name]! You made a profit of $[profit] from selling your dog.”
Write what you are looking for, and press enter to begin your search!