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 Asset with the below attributes:
• asset id, a unique id for the Asset
• asset type, type of the Asset
• asset status, status of the Asset (allocated/unallocated)
• asset owner, name of the employee to whom Asset is allocated. For unallocated Assets, the value of this attribute will remain None.
Write the code to define a method inside the class which takes as argument values for asset id, asset type, and asset owner and sets the value of attributes to parameter values. Value for asset status will be set as "unallocated" if the value for asset owner is passed as None(irrespective of cases), otherwise will be set as "allocated".
Write the code to define another class to create Asset Manager objects with the below attribute :
• a List having Asset objects
Write the code to define a method inside the class which take as an argument a list of Assets and set the value of the attribute to the parameter value
Write two methods in the Asset Manager class for the following requirements:
1. First Method: This method will count the number of unallocated assets in each type available in the Asset list of an Asset Management object and return in the form of a key: value pairs the "asset type : count Make sure that the keys should be in alphabetical order.
2. Second Method: This method will take an input parameter a list of employees' names and a type of Asset. To all eligible names in the list passed as an argument, the method will find the unallocated Assets of the given type from the Asset list and allocate the Assets to that owner.
The method will update the value of the asset status attribute of the Asset objects to "allocated", and update the value of the asset owner attribute to the name of the employee.
An employee can own multiple assets but of a specific type. Hence, a given name is eligible to be allocated to an unallocated Asset of the given type if no Asset of the given type in the Asset list is already allocated to that name
While allocating Asset, the method will follow the below rules:
1. consider the names of employees in the input order (first come first serve)
2. employee name with no allocated Asset in the Asset List will be considered first.
For example,
• names passed (as argument): Arun, Rajesh, Kamal, Raktim
• asset type: desktop.
• Given: There is only one unallocated Asset of type desktop and Arun owns desktop and Raktim owns a laptop.
Rajesh and Kamal are eligible candidates. Raktim is eligible but owns a desktop so he won't be considered.
But the unallocated Asset found will be allocated to Rajesh as this name appears before Kamal in the input list.
The method will return the count of objects updated. If the method can not update the status of any of the Asset objects in the Asset List, the method will return 0.
Note:
All the string comparisons are case insensitive These methods should be called from the main sectionInstruction to define the main function:
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 in line to the "sample input description section" mentioned below and to read the data in the same sequence.
C. Create the respective objects( Asset and Asset Manager) with the given sequence of arguments to fulfill the requirement of the methods defined in the classes referring to the below instructions: 1. Create a list of Asset objects which will be provided to the Asset Manager object to be created. To create the List,
a. Read a number for the count of Asset objects to be created and added to the list.
b. Create an Asset object after reading the data (asset id, asset type, and asset owner) related to it and add the object to the list of Asset objects. This point repeats for the number of Asset objects (considered in the first line of input) point #c.1.a. 2. Create an Asset Manager object by passing the List of Asset objects (created in above point # Test Results Cus TAKING YOU TO A NEW REALITY
Read ALL Me List of Asset objects created in above point # c. 1) as the argument
, d. Create a list of employee names to be passed as an argument to the second method (method to allocate assets of a given type to the given list of employee names).
To create the list read 3 names one by one and add them to the list.
e. Read a value for asset type to be passed as an argument to the second method (method to allocate asset of a given type to given list of employee names)
f. Call the first method (method to count the number of unallocated assets in each type) of the Asset Manager class by using the object created in point #c.2. and display the values returned by the method as below:
asset type : count.
Note: The first character of the asset type should be printed in the upper case irrespective of the value of the asset type in the list returned. You may refer to the sample output for the display format.
g. Call the Second method of the Asset Manager class by using the object created in point #c2 with the list created in point #d and the value read in point #e as arguments. If the method returns 0, print "No Asset allocated" (excluding the quotes). Otherwise print "Count of records updated: <value returned by the method >" (excluding the quotes) Followed by that, in the next line print the asset id and the asset owner of all the assets in the Asset list of the Asset Manager object created.
Note:
• For each Asset, the value should be printed in a new line.
• Value should be printed in the order the objects appear in the Asset List of the Asset Management object in the order input values are given).
You can use/refer to the below-given sample input and output to verify your solution using the Test against Custom Input' option in Hackerrank.
Sample Input (below) description:
The 1st input taken in the main section is the number of Asset objects to be added to the list of Asset Manager object created
The next set of inputs are the asset id, asset type, asset owner for each Asset object taken one after other and is repeated for number of Asset objects given in the first line of input
Take three values for list of names to be passed to the second method defined in the Asset Manager class as the first argument.
The last input is the asset type to be supplied as the second argument to the second method defined in the Asset Manager class.SAMPLE TEST CASE 1
Input:
4
1001
Laptop
Sonal Sharma
1002
Desktop
None
1003
Laptop
None
1004
Desktop
Arun Singh
Sonal Sharma
Tarun Singh
Ruby Tamuli
Desktop
output 1:
Desktop : 1
Laptop : 1
Count of records updated: 1
1001 Sonal Sharma
1002 Tarun Singh
1003 none
1004 Arun Singh
Sample testcase 2
Input
4
1001
Laptop
Sonal Sharma
1002
Laptop
None
1003
Laptop
None
1004
Desktop
Taru Singh
Arun Singh
Sonal Sharma
Ruby Tamuli
Desktop
Output:
Laptop:2
No Asset allocated
SOLUTION VIDEO FOR THIS QUESTION:
TCS IRA PYTHON SOLUTION 7TH MARCH 2022
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