IN THIS BLOGPOST I AM GOING TO SHARE THE 27TH DEC PYTHON QUESTION AND SOLUTION.HOPE THIS IS HELPFUL TO YOU.
Xperience IRA Dec 29th 2021_Python: Vaccination Drive
Write code to define the class to create Vaccine objects with the below attributes:
Vaccine Id (a unique id for the Vaccine)
Vaccine Name (name of the Vaccine)
Start Due Month (the minimum age in terms of months when the Vaccine can be
taken)
End Due Month (the maximum age in terms of months when the Vaccine can be
taken)
Define a method in the class which takes the parameters values for attributes in the
above sequence and set the value of attributes to parameter values while creating a
Vaccine object
Note: The value for start Due Month should not be higher than the value
for end Due Month. If the input value for start Due Month>end Due Month,
method should interchange the values before setting to the attribute.
Write the code to define another class to create Child objects with the
below attributes:
Name of the child - a unique string value
Date of Birth represented as a string in the format ddmmyyyy
Age In Months (current age of the Child in months. e.g 3/4)
Vaccination Details stored as key:value pairs the vaccine id and the vaccination
date the date when Vaccine was taken,
Note: No two child will have same name
Write the code to define a method which takes parameter values for all four attributes in the above sequence and set the value of attributes to parameter values when a Child object is created
Define a function/method which is not part of any class to fulfill the below requirement:
Method will take as input
1. a list of Vaccine objects
2. a Child object
3. a string representing date (vaccination Date) in the format ddmmyyyy.
The method will find the Vaccine from the Vaccine List passed as argument that can be given to the Child passed as the second argument based on the age of the Child (age In Months)
If a Vaccine applicable for the Child is found in the vaccine list given, the vaccination Details of the Child is updated by adding the "vaccine Id: vaccination Date" to the existing vaccination details of the child.
A Vaccine is considered applicable to a Child only when the following conditions are fulfilled:
• if the age in month of the Child (age In Months) is not less than the Start Due Month of the Vaccine and not greater than the End Due Month of the Vaccine.
• if the vaccine is not already given to the Child. That is the id of the Vaccine (vaccine not present in the vaccination Details of the Child.
If suitable Vaccine for the Child can be found, method will return True after updating the Vaccination Details of the Child, otherwise method will return false.
Write the code to define another function/method which is not part of any class to fulfill the below requirements :
Method will take as input
1. a list of Vaccine objects
2. a list of Child objects
3. a string representing date (Vaccination Date) in the format ddmmyyyy.
Method will update the Vaccination Details of all Child objects in the child List passed as the second argument based on the Vaccine details passed as the first argument as per the criteria defined for the first method definition and will return the count of Child objects that could be vaccinated. If no child could be vaccinated, method will return 0.
To update the vaccination Details of Child object, previously defined method can be used.
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(Vaccine and Child) with the given sequence of arguments to fulfill the requirements defined in the respective classes referring to the below instructions.
1. Create a list of Vaccine objects(e.g. vaccine List) which will be provided as
argument to the methods defined above to vaccinate a Child' and 'vaccinate a list of Child objects' respectively.
To create the list:
a. Read a number representing how many Vaccine objects to be created.
b. Read data related to attributes of Vaccine (i.e. Vaccine Id, Vaccine Name, Start Due Month, End Due Month) create the Vaccine object and add the object to the list
This point repeats for the number of Vaccine objects to be created (considered in the first line of input, #1.a).
2. Create a list of Child objects (e.g. child List) which will be provided as argument to the method defined above to vaccinate a list of Child objects.
To create the list a. Read a number for how many Child objects to be added to the list.
b. Read data related to attributes of the Child - Name, Date Of Birth, Age In Months and Vaccination Details and create a Child object and add to the list.
For Vaccination Details .create a dictionary of 2 elements( vaccine id : vaccination Date):
I. read a number representing the vaccine Id (the key for the vaccine Id: vaccination Date pair) and consider the value read for Date of Birth of Child as the value for the vaccination Date and add the pair to the dictionary. This point repeats for 2 elements to be added to the dictionary.
This point (#2.b) repeats for the number of Child objects to be added to the list (value taken as the input in point #2.a).
d. Take a string value as input representing the Vaccination Date to be provided as argument to both the methods defined above Le, to vaccinate a Child and vaccinate a list of Child objects respectively
e. Call the method defined above topaccinate a Child by passing the vaccine List created in point #1, the first Child object from the child List created in point #2 and the Vaccination Date read in point #d.
If the method returns value True, print "Vaccination Successful For" (excluding the quotes) followed by the name of the first Child object from the child List created in point #2 in the same line. (for more clarity, refer to the sample input/output given).
if the method returns False, print "Vaccination Not Successful." (excluding the quotes)
F. Call the method defined above to vaccinate a list of Child objects from the main section by passing the vaccinelist created in point #1. the childList created in point #2 and the Vaccination Date read in point #d.
g. If the method defined above to vaccinate a list of Child objects returns a value greater than 0, the message "Count of Children Vaccinated" (excluding the quotes followed by the value returned by the method in the same line.
Followed by this, Print the name of the Child followed by vaccine Id and vaccination Date of all the Child objects in the child ist created in point #2 in new lines as below:
(for more clarity, refer to the sample input/output given)
If the method returns 0, print the message "No child vaccinated." (excluding the quotes)
Note : For more clarity on output vormat, kindly refer to the sample input/output given.
You can use/refer to the below given sample input and output to verify your solution using Test against Custom Input option in Hackerrank.
Input Format for Custom Testing
1/The 1st Input taken in the main section is the number of Vaccine objects to be added to the list of Vaccines,
2. The next set of inputs are the id, name, Start Due Month and End Due Month for each Vaccine taken one after the other and is repeated for number of objects given in the first line of input (point #1)
3. The next input is the number of Child objects (n) to be added to the list of Child objects.
4. The next set of inputs are the attribute values for n Child objects - the name, dob, Age In Month and the values for 2 vaccine Ids for 2 key:value pairs to be added to the Vaccination Details dictionary taken one after other
5. The last but one line of input is the Vaccination Date value to be passed as argument to the methods defined above.
Sample Test Cases: Input 1:
3
101
HepB
1
2
102
RV
2
3
103
DTaP
4
6
2
Pinkey
12022021
3
100
102
Raju
10042021
4
100
102
05062021
Output1:
Vaccination Successful For Pinkey
Count Of Children Vaccinated = 1
Pinkey
100 12022021
102 12022021
103 05062021
Raju
100 10042021
102 10042021
101 05062021
Input 2:
3
101
HepB
1
2
102
RV
2
3
103
DTaP
4
6
Julie
12022021
3
100
102
Raju
10042021
4
100
102
O5042021
Output2:
Vaccination Successful For Julie
No child vaccinated.
1 Comments
The Output is not corrrect for this Question
ReplyDelete