Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Question :-
- Create a class pan Make attributes id, material, brand, price and capacity.
- Write getters, setters and constructor having argument in same order as above.
- Write the Solution class and write main method and Implement two static functions namely (costliest pan) and (discounted price) in it.
- Costliest pan function : it accepts two arguments namely array of pan class objects and material of a pan.
- It return the costliest pan of the given material.
- Discounted price : it accepts two arguments namely array of pan objects and brand of pan.
- If the capacity of a pan of given brand is 500 ml then update the price to 20% discount.
- If the capacity of a pan of given brand is 1000ml then update the price to 26% discount.
- In the main function take the input of variable for 4 class objects.
- Take material as input and then take brand as input for passing to different function.
- Call the costliest pan function and print the id of the object returned.
- Call the discounted price function and print the new value after updation.
- """
- # Answer Code
- class pan:
- def __init__(self, id, material, brand, price, capacity):
- self.__id = id
- self.__material = material
- self.__brand = brand
- self.__price = price
- self.__capacity = capacity
- def __repr__(self):
- print("Pan specifications :-")
- print(f"\tID : {self.__id}")
- print(f"\tMaterial : {self.__material}")
- print(f"\tBrand : {self.__brand}")
- print(f"\tPrice : {self.__price}")
- print(f"\tCapacity : {self.__capacity}")
- return ""
- # getters
- @property
- def Id(self):
- return self.__id
- @property
- def material(self):
- return self.__material
- @property
- def brand(self):
- return self.__brand
- @property
- def price(self):
- return self.__price
- @property
- def capacity(self):
- return self.__capacity
- # setters
- @Id.setter
- def Id(self, value):
- self.__id = value
- @material.setter
- def material(self, value):
- self.__material = value
- @brand.setter
- def brand(self, value):
- self.__brand = value
- @price.setter
- def price(self, value):
- self.__price = value
- @capacity.setter
- def capacity(self, value):
- self.__capacity = value
- def costliest_pan(arr, material):
- T1, costliest_pan = tuple(), pan(0, "", "", 0, 0)
- for i in arr:
- if i.material == material:
- T1 += (i,)
- for i in T1:
- if costliest_pan.price < i.price:
- costliest_pan = i
- print(f"ID of the Costliest Pan : {id(costliest_pan)}\n")
- def discounted_price(arr, brand):
- T1 = tuple()
- for i in arr:
- if i.brand == brand:
- T1 += (i,)
- for i in T1:
- price = i.price
- if i.capacity == 500:
- i.price = (0.8*price)
- elif i.capacity == 1000:
- i.price = (0.74*price)
- print(i)
- def main():
- L1 = []
- for i in range(4):
- Id = int(input("\nEnter the ID of the Pan : "))
- material = input("Enter the MATERIAL of the Pan : ")
- brand = input("Enter the BRAND of the Pan : ")
- price = float(input("Enter the PRICE of the Pan : "))
- capacity = int(input("Enter the CAPACITY of the Pan : "))
- L1.append(pan(Id, material, brand, price, capacity))
- check_material = input("Enter the MATERIAL of the Pan to be checked : ")
- check_brand = input("Enter the BRAND of the Pan to be checked : ")
- costliest_pan(L1, check_material)
- discounted_price(L1, check_brand)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement