satya

Friday, October 23, 2020

Program 27

                                                                             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)


Output:

>>> 
================ RESTART: D:/old/r19 lab-python/27.py ==============
Enter the Name of the product:
pen
Total Number  of items:
200
Digit price of each item:
5
Enter Number of items you want u buy:7
Regular price is charged for your order
NO Discount
 
Final costs =  35
 A 10% discount is applied for orders of between 10 and 99 items
 A 20% discount is applied for orders of 100 or more items
>>> 

==== RESTART: D:/old/r19 lab-python/27.py ===============
Enter the Name of the product:
pen
Total Number  of items:
200
Digit price of each item:
5
Enter Number of items you want u buy:79
Actual  cost is =  395
Final costs(Discount cost10%) is  =  355.5
you save= 39.5 Rupes
>>> 

===================== RESTART: D:/old/r19 lab-python/27.py =====================
Enter the Name of the product:
pen
Total Number  of items:
200
Digit price of each item:
5
Enter Number of items you want u buy:150
Actual  cost is =  750
Final costs(Discount cost20%) =  600.0
you save= 150.0 Rupes
>>> 

No comments:

Post a Comment

Program 30

                                                                         Program 30 Write a Python class to implement pow(x, n). class Pow1:...