John bought a bicycle for $250 and a helmet for $50. Later, he sold the bicycle for $400. Write a Python program to calculate how much profit John made from selling his bicycle.
Start by asking for John’s name and store it in a variable called name
.
Define variables for the costs:
Store the cost of the bicycle in a variable called cost_of_bicycle
and set it to 250.
Store the cost of the helmet in a variable called cost_of_helmet
and set it to 50.
Store the selling price of the bicycle in a variable called selling_price_of_bicycle
and set it to 400.
Calculate the total amount John spent by adding the cost of the bicycle and the cost of the helmet.
Calculate the profit by subtracting the total amount spent from the selling price of the bicycle.
Store the profit in a variable called profit
.
Print a message that includes John’s name and the profit in a friendly sentence, like this:
“Hi [name]! You made a profit of $[profit] from selling your bicycle.”
We’re always looking for international STEM educators to join our team. If you are interested, please send us a mail and we’ll get back to you!
If you have any questions, kindly send us a mail. Don’t forget to follow and like all our social accounts to get updates on competitions!