Header Ads

Create a function that takes two arguments: the original price and the discount percentage as integers and returns the final price after the discount.

 Question Source


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:


Post a Comment

0 Comments