wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

XYZ store plans to give a festival discount to its customers. The store management has decided to give discount on the following criteria:
Shopping Amount Discount Offered
>=500 and <1000 5%
>=1000 and <2000 8%
>=2000 10%

An additional discount of 5% is given to customers who are the members of the store. Create a program using user defined function that accepts the shopping amount as a parameter and calculates discount and net amount payable on the basis of the following conditions:
Net Payable Amount = Total Shopping Amount – Discount.


Open in App
Solution

In this program, the shopping amount needs to be compared multiple times, hence ‘elif’ function will be used after first ‘if’.
If the comparison is started from the highest amount, each subsequent comparison will eliminate the need to compare maximum value.

Program:
# function definition,
def discount(amount, member):
disc = 0
if amount >= 2000:
disc = round((10 + member) * amount/100, 2)
elif amount>= 1000:
disc = round((8 + member) * amount/100, 2)
elif amount >= 500:
disc = round((5 + member) * amount/100, 2)
payable = amount - disc
print("Discount Amount: ",disc)
print("Net Payable Amount: ", payable)

amount = float(input("Enter the shopping amount: "))
member = input("Is the Customer a member?(Y/N) ")
if(member == "y" or member == "Y"):
#Calling the function with member value 5
discount(amount,5)
else:

#if customer is not a member, the value of member is passed as 0
discount(amount, 0)

OUTPUT:
Enter the shopping amount: 2500
Is the Customer a member?(Y/N) Y
Discount Amount: 375.0
Net Payable Amount: 2125.0


ā€‹ā€‹ā€‹Enter the shopping amount: 2500
Is the Customer a member?(Y/N) N
Discount Amount: 250.0
Net Payable Amount: 2250.0

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Estimation of Amounts (In Percentages)_Tackle
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon