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 a Product object with following attributes
• Product Id
• Product Brand
• Product Type
• Unit Price
• Quantity in hand Status
Write the code to define a method which takes parameters in above sequence for Product Id, Product Brand, Product Type Unit Price and Quantity in hand and sets the values for attributes while creating a Product object for the attribute Status a default value of "Available" is set.
Write the code to define another class to create a Shipping Company object with attribute as below
• A List of Product Objects
• Shipping Charge List A list which maintains the names of the cities to which product is shipped
along with the applicable shipping charge as city name : shipping charge' as key value pairs
Write the code to define the method to initialize the attributes in the above sequence while creating a Shipping Company object Create a second method inside the Shipping Company class to calculate the bill for an order for a Product of a given brand, type in a given quantity to be shipped to a given city
The method will take 4 arguments as below and return the folal bill -
1. A value depicting a Product brand as the 18 argument
2. A value depicting a Product type as the 2nd argument
3. A value representing the name of a city as the 3rd argument
4. A value representing the required quantity of Products as the 4th argument
From the Product List of the Shipping Company, method will look for a Product having Product Brand and Product Type value same as the values passed as 1st and 2nd arguments and the quantity in hand of the Product should be higher than or equal to the required quantity value passed as the 4th argument. If a Product fulfilling these conditions is found, method will find the applicable Shipping charge from the Shipping charge list of the Shipping Company for the city passed as the 3rd argument and calculate the total bill as below:
total bill Unit price *required quantity of products (value passed as the 4th argument) + Shipping Charge required quantity of products (value passed as the 4th argument).
This total bill will be calculated only if the name of the city passed as the 3rd argument is present in the Shipping charge list of the Shipping Company
If the bill can be calculated, method will return the calculated bill and update the value of quantity in hand of the Product found in the Product List of the Shipping Company by deducting the required quantity (value passed as the 4th argument) from it. If the updated quantity in hand becomes the status of the Product will be made 'unavailable"
If no Product having the given product brand and product type or having sufficient quantity in hand is available, method will return None. Also, if the name of the city passed as the 3rd argument is not present in the Shipping charge list of the Shipping Company, method will return None.
Note:
. All string comparisons should be case insensitive
• Assume there can be more than one Products of same type but there will not be more than one
Products of same type from same brand
Create a third method inside the Shipping Company class to find the product type wise count of brands for which Product is available in the updated Product List of the Shipping Company
Method will retum as a list of key:value pairs the product type wise count of available product brands (product type: count of available brands) If no valid Products found, method will return None.
Note: In the list to be returned the first character of the string for Product Type should be in upper case. For more clarity please refer to the sample input and output below.
Instructions to write main section of the code
a. You would require to write the main section completely, hence please follow the below instructions for the same b. You would require to write the main program which is inine to the sample input description section mentioned below and to read the data in the same sequence c. Create the respective objects Product and Shipping Company) with the given sequence of c. Create the respective objects (Product and Shipping Company) with the given sequence of arguments to fulfill the method requirement defined in the respective classes referring to the below instructions i. Create a list of Products. To create the list
1. First read the number of Products you want to store in the list.
2. Read the values for the attributes of the Product (Product id. Product Brand, Product Type, Unit Price, Quantity in hand) in the same sequence, create the product object and add it to the product list. This point repeats for the number of Products (consider the input taken in point #1 above) to be created ii. Create a list of "city name : shipping charge" as key value pairs for the Shipping Charges List of the Shipping Company. To create the list.
1. First read the number of elements you want to store in the list.
2. Read the values for the city name and corresponding shipping charge and add the values as key:value paid to the list. This point repeats for the number of elements (consider the input taken in point #il.1 above) to be created. ili Create Shipping Company object by passing the list of Product objects created as mentioned in point #ci and the Shipping Charges list created in point #c.il d. Read values for Product Brand Product Type, name of a city and the required quantity of product to be passed as argument to the 2nd method defined in the Shipping Company class e. Call the 2nd method defined in the Shipping Company class by using the Shipping Company object created in point #c.il from the main section f. Display the message "Bill Calculated" (excluding the quotes). Display the bill value returned by the method called in point #e in the same line. If the method retums None, display the message "Product Not Found." (excluding the quotes). g. Call the 3rd method defined in the Shipping Company class by using the object created in point #c.il from the main section. h. Display the values returned by the method called in point #g as in separate lines in ascending order of the Product Type.
If the method returns None, display the message No Products found' (excluding the quotes) Please refer to the sample output given for reference for more clarity on output formats.
You can use/refer the below given sample input and output to verify your solution Input Format for Custom Testing
a. The 1st input taken in the main section is the number of Product objects to be added to the list of Products b. The next set of inputs are the values related to attributes of Product objects to be added to the list.
Product id. Product Brand, Product Type, Unit Price Quantity in hand The above point repeats for the number of Product objects, read in pointia
The next input is the count of elements (key value pairs) to be added to the Shipping Charges List of the Shipping Company class. d. The next set of inputs are the values for city name and corresponding shipping charge which is repeated for the number of elements mentioned in point e. The last four lines of input refer to the input Product Brand, Product Type, city name and required product quantity to be passed as argument to the 2nd method of the Shipping Company Class
You can consider below sample input and output to verify your implementation before submitting in Hackerrank
Sample input 1
5
1011
Leo
Electronic
300
20
1012
Ledo
Electronic
350
50
1021
Leo
Puzzle
100
20
1022
Leo
mechanics
400
30
1023
FunkCool
puzzle
350
20
3
Guwahati
50
Kolkata
30
Shillong
100
Leo
Electronic
Shillong
20
Output:
Bill Calculated:8000
Electronic:2
Mechanics:1
Puzzle:2
Sample input 2:
5
1011
Leo
Electronic
300
20
1012
Ledo
Electronic
350
50
1021
Leo
Puzzle
100
20
1022
Leo
mechanics
400
30
1023
Funk Cool
puzzle
350
20
3
Guwahati
50
Kolkate
30
Shillong
100
Leo
Electronic
Delhi
20
output:
Product Not Found
Electronic:2
Mechanic:1
Puzzle:2
SOLUTION FOR THIS QUESTION VIDEO:
HOPE THIS IS HELPFUL TO YOU GUYS.IF YOU LIKE MY WORK ,CONSIDER SUBSCRIBING TO MY CHANNEL AND FOLLOW MY BLOGPOST FOR MORE UPDATES
0 Comments