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:

  1. 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.

  2. User Inputs:

    • amount: Input for the total shopping amount.

    • member_status: Input to check if the customer is a member.

  3. 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.


Was this helpful?

India's 1st AI Doubt Solver for CBSE, JEE, and NEET

Ask a Question for Free

and then it's just ₹212 a month

Learn how Chatterbot AI can help you succeed

Cover Image of the article Computer Science Class 11 CBSE - The Ultimate Guide with Notes, Solutions and AI

Computer Science Class 11 CBSE - The Ultimate Guide with Notes, Solutions and AI

This ultimate guide for CBSE Computer Science class 11 has detailed notes, NCERT solutions, cheat sheets, and our free AI-powered doubt-solving assistant, Chatterbot AI.

Cover Image of the article JEE Advanced 2024 Exam Date Announced: Complete Guide to Eligibility, Syllabus, and Preparation Tips

JEE Advanced 2024 Exam Date Announced: Complete Guide to Eligibility, Syllabus, and Preparation Tips

JEE Advanced 2024 on May 26! Get exam schedule, syllabus, prep tips & more in this guide. Ace India's top engineering test with topper strategies.

Cover Image of the article How to Crack NEET: The Ultimate Blueprint to Outsmart the Exam and Unlock Your Medical Dreams

How to Crack NEET: The Ultimate Blueprint to Outsmart the Exam and Unlock Your Medical Dreams

Ace NEET with expert strategies: Discover effective exam strategies, time management, core concepts mastery, problem-solving techniques, revision tips, and AI-assisted doubt clearing with Chatterbot AI.

Cover Image of the article How to Crack IIT: Smart Self-Study Strategies and AI Tools for Success

How to Crack IIT: Smart Self-Study Strategies and AI Tools for Success

Ace IIT JEE in 6 months without coaching. Discover expert self-study strategies for Physics, Chemistry, and Math. Master time management, mock tests, and leverage AI tools like Chatterbot AI for personalized doubt-solving.