Discount Calculator
Calculate a discount and payable price with Python. Students convert a percentage, subtract its monetary value, and display original, saved, and final amounts.
1# Take inputs2price = float(input("Enter price: "))3discount_percent = float(input("Enter discount (%): "))45# Calculate6discount_amount = (price * discount_percent) / 1007final_price = price - discount_amount89print(f"Original price: {price:.2f}")10print(f"Discount ({discount_percent}%): {discount_amount:.2f}")11print(f"Final price: {final_price:.2f}")
Output
Enter price: 1000 Enter discount (%): 20 Original price: 1000.00 Discount (20.0%): 200.00 Final price: 800.00
In this one
- Convert a percent reduction
- Subtract the monetary discount
- Keep monetary quantities separate
How it works
- 1
Read price and discount_percent.
- 2
Calculate price * discount_percent / 100.
- 3
Subtract that amount and display all three values.
Edge cases
What does a zero-percent discount do?
What does a zero-percent discount do?
It leaves the final price equal to the original.
Does the code reject discounts above 100?
Does the code reject discounts above 100?
No. Such input can produce a negative final price.
What's going on
discount_amount is price * discount_percent / 100. Subtracting it from price produces final_price.
For a price of one hundred and a ten-percent discount, the reduction is ten and the result ninety. .2f controls displayed decimals only. The example accepts any numeric percent, so negative or above-one-hundred discounts can produce unusual results without validation.
What does a zero-percent discount do? It leaves the final price equal to the original.
Does the code reject discounts above 100? No. Such input can produce a negative final price.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What is subtracted from price?
Pick an answer to check it.
Question 2
What does a zero-percent discount do?
Pick an answer to check it.
Questions people ask
What does a zero-percent discount do?
It leaves the final price equal to the original.
Does the code reject discounts above 100?
No. Such input can produce a negative final price.
What is subtracted from price?
The calculated discount amount.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum