Program 27
Write a class called Product. The class should have fields called name, amount, and price, holding the product’s name, the number of items of that product in stock, and the regular price of the product. There should be a method get_price that receives the number of items to be bought and returns a the cost of buying that many items, where the regular price is charged for orders of less than 10 items, a 10% discount is applied for orders of between 10 and 99 items, and a 20% discount is applied for orders of 100 or more items. There should also be a method called make_purchase that receives the number of items to be bought and decreases amount by that much.
class Product:
def __init__(self, name, total_items, price):
self.name = name
self.total_items = total_items
self.price = price
def get_price(self, number_to_be_bought):
discount = 0
if number_to_be_bought < 10:
print("Regular price is charged for your order")
print("NO Discount\n ")
cost=self.price * number_to_be_bought
print('Final costs = ',cost)
print(" A 10% discount is applied for orders of between 10 and 99 items")
print(" A 20% discount is applied for orders of 100 or more items")
elif 10 <= number_to_be_bought < 99:
Actual_cost=self.price * number_to_be_bought
print('Actual cost is = ',Actual_cost)
discount = 10
p = (100 - discount) / 100 * self.price
cost=p * number_to_be_bought
print('Final costs(Discount cost10%) is = ',cost)
print("you save=",Actual_cost-cost,"Rupes")
else:
Actual_cost=self.price * number_to_be_bought
print('Actual cost is = ',Actual_cost)
discount = 20
p = (100 - discount) / 100 * self.price
cost=p * number_to_be_bought
print('Final costs(Discount cost20%) = ',cost,)
print("you save=",Actual_cost-cost,"Rupes")
name=input("Enter the Name of the product:\n")
total_items=int(input('Total Number of items:\n')),
price=int(input('Digit price of each item:\n'))
p=Product(name,total_items,price)
number_to_be_bought=int(input("Enter Number of items you want u buy:"))
p.get_price(number_to_be_bought)
No comments:
Post a Comment