Advertisement
Programmin-in-Python

Code for the Pan Object Question

Feb 18th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.31 KB | None | 0 0
  1. """
  2. Question :-
  3.  
  4. Create a class pan Make attributes id, material, brand, price and capacity.
  5. Write getters, setters and constructor having argument in same order as above.
  6. Write the Solution class and write main method and Implement two static functions namely (costliest pan) and (discounted price) in it.
  7.  
  8. Costliest pan function : it accepts two arguments namely array of pan class objects and material of a pan.
  9.     It return the costliest pan of the given material.
  10.  
  11. Discounted price : it accepts two arguments namely array of pan objects and brand of pan.
  12.     If the capacity of a pan of given brand is 500 ml then update the price to 20% discount.
  13.     If the capacity of a pan of given brand is 1000ml then update the price to 26% discount.
  14.  
  15. In the main function take the input of variable for 4 class objects.
  16. Take material as input and then take brand as input for passing to different function.
  17. Call the costliest pan function and print the id of the object returned.
  18. Call the discounted price function and print the new value after updation.
  19. """
  20.  
  21. # Answer Code
  22.  
  23. class pan:
  24.     def __init__(self, id, material, brand, price, capacity):
  25.         self.__id = id
  26.         self.__material = material
  27.         self.__brand = brand
  28.         self.__price = price
  29.         self.__capacity = capacity
  30.  
  31.     def __repr__(self):
  32.         print("Pan specifications :-")
  33.         print(f"\tID : {self.__id}")
  34.         print(f"\tMaterial : {self.__material}")
  35.         print(f"\tBrand : {self.__brand}")
  36.         print(f"\tPrice : {self.__price}")
  37.         print(f"\tCapacity : {self.__capacity}")
  38.  
  39.         return ""
  40.  
  41.     # getters
  42.     @property
  43.     def Id(self):
  44.         return self.__id
  45.  
  46.     @property
  47.     def material(self):
  48.         return self.__material
  49.  
  50.     @property
  51.     def brand(self):
  52.         return self.__brand
  53.  
  54.     @property
  55.     def price(self):
  56.         return self.__price
  57.  
  58.     @property
  59.     def capacity(self):
  60.         return self.__capacity
  61.  
  62.     # setters
  63.     @Id.setter
  64.     def Id(self, value):
  65.         self.__id = value
  66.  
  67.     @material.setter
  68.     def material(self, value):
  69.         self.__material = value
  70.  
  71.     @brand.setter
  72.     def brand(self, value):
  73.         self.__brand = value
  74.  
  75.     @price.setter
  76.     def price(self, value):
  77.         self.__price = value
  78.  
  79.     @capacity.setter
  80.     def capacity(self, value):
  81.         self.__capacity = value
  82.  
  83. def costliest_pan(arr, material):
  84.     T1, costliest_pan = tuple(), pan(0, "", "", 0,  0)
  85.  
  86.     for i in arr:
  87.         if i.material == material:
  88.             T1 += (i,)
  89.  
  90.     for i in T1:
  91.         if costliest_pan.price < i.price:
  92.             costliest_pan = i
  93.  
  94.     print(f"ID of the Costliest Pan : {id(costliest_pan)}\n")
  95.  
  96. def discounted_price(arr, brand):
  97.     T1 =  tuple()
  98.  
  99.     for i in arr:
  100.         if i.brand == brand:
  101.             T1 += (i,)
  102.  
  103.     for i in T1:
  104.         price = i.price
  105.         if i.capacity == 500:
  106.             i.price = (0.8*price)          
  107.  
  108.         elif i.capacity == 1000:
  109.             i.price = (0.74*price)
  110.            
  111.         print(i)
  112.  
  113. def main():
  114.     L1 = []
  115.  
  116.     for i in range(4):
  117.         Id = int(input("\nEnter the ID of the Pan : "))
  118.         material = input("Enter the MATERIAL of the Pan : ")
  119.         brand = input("Enter the BRAND of the Pan : ")
  120.         price = float(input("Enter the PRICE of the Pan : "))
  121.         capacity = int(input("Enter the CAPACITY of the Pan : "))
  122.  
  123.         L1.append(pan(Id, material, brand, price, capacity))   
  124.  
  125.     check_material = input("Enter the MATERIAL of the Pan to be checked : ")
  126.     check_brand = input("Enter the BRAND of the Pan to be checked : ")
  127.  
  128.     costliest_pan(L1, check_material)
  129.     discounted_price(L1, check_brand)
  130.  
  131. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement