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.
Python_SBQ_IRA 20TH Dec:EMPLOYEE LEAVE MANAGEMENT.
An organization wants an application to automate the activities related to Employees,
Leave policy and Leaves taken by Employees. Organization maintains the details of it's
employees like
the name( TYPE STRING)
the department name(TYPE STRING)
salary (TYPE INT)
Each employee maintains the
record of different type of leaves he/she has taken as the type of the leave and count of
days leave was taken. (TYPE DICT)
Organization maintains the details of types of leave offered to
employees along with the maximum number of days the employee can take that leave in a
year.
Time to time, organization keeps updating its leave details by adding a new leave type or deleting a leave type or changing the maximum allowable count of days for a leave type .Employee can request for leave only of the types available and can take in total leave of a specific type up to the maximum number of days allowed
Write the code to define a class to create an employee object with the below attributes:
name of the employee
the name of the Department employee works for
employee's salary
records of leaves taken by the Employee which captures the count of leaves the employee
has taken for each leave type available in the organization.
Define a method to initialize the attributes when an Employee object is created
Define another class to create an organization object with the below attributes:
A List having Employee
A dictionary to record the types of leave allowed by the Organization and the allowed
maximum count of leaves for each leave type as key value pairs
This dictionary is used as the database to keep track of different types of leaves offered to the employees of the Organization along with the maximum count of days allowed for that type of leave
1.Define a method in the class to initialize the attributes when an organization object is created
Create another method inside the class to fulfill the requirement described below:
2.Purpose of this method is to update the dictionary for leave type and the allowed maximum count of leaves for each leave type of the organization time to time by incrementing or decrementing the allowed maximum count of leave of a given leave type.
The method takes three arguments -
1. A value for a leave type (the key of the key value pair of the dictionary)
2. A number by which the allowed maximum count of leaves is to be incremented or
decremented for the given leave type.
3. A string as "increment" or "decrement" to represent whether the allowed maximum
count of leaves of the given leave type is to be incremented or decremented by the
days passed as argument.
Method will do the following things
• Method will check if the leave type given as the argument is present as a key for one of the key value pairs in the dictionary for leave records of the Organization If it is
present and if the value passed as the argument is increment, the value of the days
for that leave type is incremented by the value passed as the argument for number of
days and if it is "decrement", the value of the days for that leave type is decremented
by the value passed as the argument for number of days
• If the leave type given as the first argument is not present as a key for any of the
key value pairs in the dictionary, method adds a new element (a key value pair ) to the
dictionary considering the values passed as arguments for leave type and the number
of days as the key value pair
• The value for allowed maximum count of leaves cannot be negative. Hence, the value
should be considered as 0 in case, in decrementing the value for the days it becomes -
ve.
• Method does not return anything.
• While treating the strings passed as argument, it should be case insensitive.
Create another method in the Organization class for the following
Method takes as argument -
1. A string representing the name of an employee.
2. A string representing a leave type.
3. A number representing the number of days the employee wants to take leave.
Method will first check if the Employee is eligible for the leave or not
If it finds the employee eligible for the leave, then it will return True and will record the leave details in the leave record dictionary of the Employee class by updating (incrementing) the count value of the leave Type leave Count pair, if the value passed for leave type as the argument is present as a key in the leave record dictionary in employee class Otherwise, it will add a new element (a key value pair ) to the dictionary considering the values passed as arguments for the leave type and the number of days as the key : value pair
An Employee will be considered as eligible for the requested leave only when the
following conditions are fulfilled :
1. An employee with the name passed as the first argument is present in the Employee List
of the organization
2. The leave type given as the argument is present in the leave record dictionary of the
organization as a key
3. The summation of existing count of leaves taken and the number of days the
employee wants to take leave for the given leave type should not be greater than the
allowed maximum count of leaves for that leave type in the leave record dictionary of the organization
If any of these conditions is not fulfilled, method returns False.
Note:
• Consider there are no two employees with the same name.
• All string comparisons should be case sensitive
• Display order for leave types in output should be the same as input order of data.
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 inline to the "sample input
description section" mentioned below and to read the data in the same sequence.
c. Create the respective objects(Employee and Organization) with the given sequence of
arguments to fulfill the __init__method requirement defined in the respective classes
referring to the below instructions.
i. Create a list of Employee objects. To create the list,
1. Take as input, the count of elements you want to add to the dictionary
2. Create a leave Type:days (key:value) pair after reading the data related to it and
add the pair to the dictionary which will be provided to the Organization object while
creating the Object. This point repeats for the number of leave type:days pair you want to
1. Take as input, the count of elements you want to add to the dictionary
2. Create a leave Type:days (key value) pair after reading the data related to it and
add the pair to the dictionary which will be provided to the Organization object while
creating the Object. This point repeats for the number of leave type:days pair you want to
add to the dictionary (considered as input in point #c.ii. 1).
iii. Create Organization object by passing the List of Employee objects ( created in point
ci) and the dictionary (created in point #cil) as the arguments.
d. Take a string value as leave type, a number value for the days and a string
("increment"/"decrement") to be provided as arguments to the method of the Organization
to be used to update leave type.
e. Take a string as employee name followed by another string as leave type and followed
by a number as days to be passed as arguments to the method of the Organization to be
used to apply leave by an employee.
f. Take a string as leave type and followed by a number as days to be passed as arguments
to the method of the Organization to be used to apply leave by an employee. Note: the
method is to be called for the same employee as point #e.
g. Call the method to be used to update Leave Type mentioned above from the main
section with the data read in point #d.
h. Display a message "Organization's Leave Database after update :" (excluding quotes)
i. Display the updated leave type and days for each key value pairs in the leave record
dictionary of the Organization object created in point #c.iii.
j. Call the method to be used to apply Leave with the data read in point #e and if the value
returned by the method is True, display "Employee is eligible for leave" (excluding the
quotes) followed by "Count of Leave taken : <count of the leave taken on the given
category as per the Employee's leave record dictionary>" (excluding quotes).
If the method returns False, display "Employee is not eligible for leave" (excluding the
quotes)
k Call the method be used to apply Leave again with the name read in step te and the
data read in step #f and if the value returned by the method is True, display "Employee is
eligible for leave" (excluding the quotes) followed by "Count of Leave taken: <count of the
leave taken on the given category as per the Employee's leave record
ALL
If the method returns False, display "Employee is not eligible for leave" (excluding the
quotes)
You may refer to the sample output for the display format
You can use/refer the below given sample input and output to verify your solution using
Test against Custom Input ' option in Hackerrank.
2
Input Format for Custom Testing
***
The 1st input taken in the main section is the number of Employee objects to be added to
the list of employee.
The next set of inputs are the employee name, department and salary for each employee
taken one after other and is repeated for number of objects given in the first line of input
The next input taken in main section is the count of key value pairs to be added to the leave
record dictionary of organization class.
The next set of inputs are the leave type and days for each leave type(key value pairs)
taken one after other and added to the dictionary and is repeated for number of pairs given
in the previous line of input
The next input is a leave type, followed by number of days to increment/ decrement the
leave count in leave record of the organization, followed by a string
("increment"/"decrement") to be passed as argument to the method to be used to update
Leave Type
The next line of input refers the employee name followed by leave type followed by days
leaves/ days count applied in the current application) to be passed as argument to the
method to be use to apply Leave
The next line of input refers the leave type followed by days( leaves/ days count applied in
the current application) to be passed as argument to the method to be use to apply
Leave called for the second time for the same employee as called for the first time.
Sample Input 1
5
Ashok
HR
25000
Ratna
Admin
20000
Deepali
Admin
23000
Deepak
Sales
30000
Sujit
Admin
26000
3
cl
5
el
10
sl
12
cl
3
increment
Ashok
cl
3
cl
3
Output
Organization's Leave Database after update
cl: 8
el : 10
sl : 12
Employee is eligible for leave
Count of Leave taken: 3
Employee is eligible for leave
Count of Leave taken : 6
In the above output: The line number 2-4 represents the master Leave record of the
Organization after calling the method defined to update Leave Type
Next two lines are based on the output from the method defined to apply Leave. Since
conditions are met as mentioned in the Question, the message "Employee is eligible for
leave" is displayed followed by the relevant message and number of leaves taken in the
current leave request i.e. 3
Next two lines are based on the output from the method defined to apply Leave after calling
second time. Since conditions are met as mentioned in the Question, the message
"Employee is eligible for leave" is displayed followed by the relevant message and number
of leaves already taken by the Employee.
HOW TO SOLVE:
FOR COMPLETE STRUCTURE AND FOR TIPS AND TRICKS TO SOLVE IRA PYTHON QUESTION.IN THIS VIDEO,I HAVE SHARE HOW TO WRITE AND READ THE QUESTION TO GET MAXIMUM VIEW OF QUESTION AND HOW TO WRITE A SOLUTION TO IT.WATCH THE ABOVE CODE AND TO PRACTICE USE THE PREWRITTEN CODE.
PYTHON 20TH DEC SOLUTION:
2 Comments
please provide online terminal same like tcs exam for practice
ReplyDeleteThe Solution is not fully Correct. You have missed a lot of things.The Output is also not according to the question
ReplyDelete