In this program we have to calculate final price after deducting the discount.
Approach :
We simply have to define a function. Calculate discount by using the formula -
discount = (original price x discount %)/100
Then subtract it from the original price and we will return the final price after rounding it off to 2 decimal places.
Code :
def dis(price, discount):
ds = price*(discount/100)
sp = price-ds
sp = round(sp, 2)
return sp
ori_price = int(input("Enter Original Price : "))
dis_per = int(input("Enter Discount Percentage : "))
print(dis(ori_price, dis_per))
Output :
Enter Original Price : 150
Enter Discount Percentage : 10
135.0
Explanation :
'dis' function is defined to do the required operations. variable ori_price takes the original price as input and dis_per takes the discount percentage as the input. These values are passed to the dis function which takes two argument price and discount. The value of calculated discount is stored in ds variable. sp stores the final price, sp is overwritten in the next line where final price is rounded off to 2 decimal places. After all these processing the value of sp is returned and printed as a output.
Related Links:
- QR Code Generator
- Selection Sort
- Print the sum of series using C programming
- Check whether a person can Drive or not using Ternary Operator
- Top 50 OOPS (Object Oriented Programming System) Interview Questions
- Animated Login page using HTML and CSS
- Write a program in Java to accept a name(Containing three words) and Display only the initials (i.e., first letter of each word).
- How can I get better at JavaScript?
0 Comments
Ask Your Queries in the comments