HELLO DORAEMONS,
IN THIS BLOGPOST ,I HAVE SHARED THE RECENTLY ASKED PYTHON QUESTION AND SOLUTION WHICH IS CERTAINLY USEFUL WHEN YOU WANT TO PRACTICE.HOPE THIS BLOG IS USEFUL TO YOU
Write the code to define a class to create objects of type Item with following attributes :
• Item ID
• Item Type
•Price
Define a method in the class which sets values to the 3 attributes by taking values as argument in the sequence mentioned above while creating a Item object
Write the code to define a Class to create a Store object with following attributes :
• A list of Item Objects
• A dictionary of key : value pairs stored for applicable discount rate for
different Item Types as " Item Type : discount rate " .
Define a method in the class which sets values to the attributes by taking values as argument in the sequence mentioned above while creating a Store object
Define two more methods inside the class to fulfill the requirements defined
below:
1. The second method will be used to find the amount to be lost by the
Store due to discount offered for a given category of Items. Method will
take as argument value for an Item Type and calculate the total discount
amount for that type of Items available in the Item list of the store based on
the discount rate for that type available in the applicable discount rates for
different item types of the Store.
Method will return the calculated value. If no Item with the given Item type
exists in the Item List of the Store or given Item Type is not available in
the applicable discount rates for different item types of the Store, method
will return None .
2. The third method will be used to calculate the discount for the Items in
the Item list of the Store and update the price by deducting the value
calculated for discount .
For each Item in the Item List of the Organization, method will calculate the
discount amount based on the Item Type and the discount rate for that Item
Type maintained by the Store. Method will update the value of the price of
the Item by deducting the discount value calculated from the price.
Discount is calculated using the following formula :
Discount = price*(discount rate/100).
If the Item Type of an Item is not found in the discount details of the Store
as key for any key-value pairs, discount applicable is considered as 0.
Method will not return any value.
For more clarity, please refer to the sample input and output below.
Note: All the searches should be case insensitive.
Instructions to write main section of the code:
1. You would require to write the main section completely, hence please
follow the below instructions for the same.
2. You would require to write the main program which is inline to the
"sample input description section" mentioned below and to read the data in
the same sequence.
3. Create the respective objects(Item and Store ) with the given sequence
of arguments to fulfill the requirements of the methods defined in the
respective classes to initialize the attributes while creating objects referring
to the below instructions.
i. Create a list of Item objects for the Store object to be created.
To create the List,
1. First read the number of Item objects you want to store in the list
2. Create a Item object after reading the data related to it -Item Id, Item
Type and Price and add the object to the list of Item objects to be provided
to the Store object for the Item List attribute. This point repeats for the
number of Item objects(considered in the first line of input) to be created .
li. Create a list of of “Item Type: discount rate” pairs for the Store object
to be created.
To create the list , read values for 3 pairs of values for “Item Type :
discount rate" and add to the list.
ili. Create Store object by passing the Item List ( created above in point #
3.1) and the list of “Item Type : discount rate" pairs (created in point #3.ii
) as the arguments .
4 Read a value for Item Type to be passed as argument to the second
method defined in the Store class.
5. Call the second method defined in the Store by passing the value read
for Item type in point #4.
6. Call the third method defined in the Store to calculate the discount for
the Items in the Item list of the Store .
7. Print the message "Price List After Discount:" excluding the quotes.
Print the Item Id , the Price after discount for each Item in the Item List of
the Store one by one .
In the output ,the details of the Item with highest price after
discount should be in the top of the list .
Refer to sample output for more details on format of the output.
8. If the value returned by the second method defined in the Store class
(called at point #5) not None , print the message "Total loss=" followed by
the value returned by the method. If the method returns None, print the
message "No loss took place” excluding quotes.
Sample Input:
4
101
Furniture
5500
102
Cosmetics
700
103
Toy
600
104
Stationary
200
Furniture
12
Cosmetics
10
electronics
10
Furniture
Output
Price List After Discount:
101 4840.0
102 700
103 600
104 200
Total loss= 660.0
0 Comments