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.
Question
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.
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Here is a Python program to calculate the discount and net payable amount based on the provided criteria using a user-defined function:
def calculate_discount(shopping_amount, is_member):
"""
This function calculates the discount and the net payable amount.
:param shopping_amount: Total shopping amount
:param is_member: Boolean indicating if the customer is a store member
:return: Net payable amount
"""
discount = 0
if shopping_amount >= 2000:
discount = 0.10
elif shopping_amount >= 1000:
discount = 0.08
elif shopping_amount >= 500:
discount = 0.05
if is_member:
discount += 0.05
discounted_amount = shopping_amount * discount
net_payable_amount = shopping_amount - discounted_amount
return net_payable_amount
# Example Usage
amount = float(input("Enter the shopping amount: "))
member_status = input("Is the customer a member (yes/no)? ").strip().lower()
if member_status == 'yes':
is_member = True
else:
is_member = False
net_amount = calculate_discount(amount, is_member)
print(f"Net Payable Amount: {net_amount:.2f}")
Explanation:
Function Definition:
calculate_discount
: This function calculates the net payable amount after applying applicable discounts.Parameters:
shopping_amount
: The total shopping amount.is_member
: Boolean indicating whether the customer is a store member.
Logic:
Based on the shopping amount and whether the customer is a member, it calculates the discount.
It then returns the net payable amount after discount.
User Inputs:
amount
: Input for the total shopping amount.member_status
: Input to check if the customer is a member.
Calling the function and displaying the result:
Pass the inputs to the
calculate_discount
function.Print the net payable amount formatted to 2 decimal places.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month