Untitled
unknown
python
9 months ago
2.2 kB
5
Indexable
class Member:
def __init__(self, customer_id, customer_name, email_id):
self.customer_id = customer_id
self.customer_name = customer_name
self.email_id = email_id
class GoldMember(Member):
def __init__(self, customer_id, customer_name, email_id):
super().__init__(customer_id, customer_name, email_id)
self.discount_amount = 0 # Initialize discount amount
def calculate_discount(self, purchase_amount):
self.discount_amount = purchase_amount * 0.1 # 10% discount
return self.discount_amount
class DiamondMember(Member):
def __init__(self, customer_id, customer_name, email_id):
super().__init__(customer_id, customer_name, email_id)
self.discount_amount = 0 # Initialize discount amount
def calculate_discount(self, purchase_amount):
self.discount_amount = purchase_amount * 0.2 # 20% discount
return self.discount_amount
def main():
print("1. Gold Membership")
print("2. Diamond Membership")
try:
choice = int(input("Enter your choice: "))
print("\nEnter the Details:")
customer_id = input("Customer ID: ")
customer_name = input("Customer Name: ")
email_id = input("Email ID: ")
purchase_amount = float(input("Enter the Purchase Amount: "))
if choice == 1:
member = GoldMember(customer_id, customer_name, email_id)
discount = member.calculate_discount(purchase_amount)
print("\nMember Details:")
print(f"ID: {member.customer_id}, Name: {member.customer_name}, Email: {member.email_id}, "
f"Discount Amount: {discount:.2f}")
elif choice == 2:
member = DiamondMember(customer_id, customer_name, email_id)
discount = member.calculate_discount(purchase_amount)
print("\nMember Details:")
print(f"ID: {member.customer_id}, Name: {member.customer_name}, Email: {member.email_id}, "
f"Discount Amount: {discount:.2f}")
else:
print("Invalid choice.")
except ValueError:
print("Invalid input. Please enter valid data.")
if __name__ == "__main__":
main()
Editor is loading...
Leave a Comment