Click here to Skip to main content
15,742,655 members
Please Sign up or sign in to vote.
1.16/5 (4 votes)
See more:
Create a class City with the below attributes: city_id of type Number state_name of type String city_name of type String covidbeds of type Number avlblcovbeds of type Number ventilbeds of type Number avlblventilbeds of type Number

Attribute description: city_id represents Unique ID for the city state_name represents the state name city_name represents the city name

covidbeds represents the total covid beds in the city avlblcovbeds represents the total available covid beds in the city ventilbeds represents the total ventilator beds in the city avlblventilbeds represents the total available ventilator beds in the city

Create the init method which takes all parameters in the above sequence. The method should set the value of attributes to parameter values .

Create another class CovBedsAnalysis with the below attributes: analysis_name of type String city_list of type List having city objects

Create the init method which takes all parameters in the above sequence. The method should set the value of attributes to parameter values inside the method.

Create another method inside the class with the name get_StateWiseAvlblBedStats

This method is used to find the state wise available covid beds and available ventilator beds and returns a list of tuples with State name,total available covid beds and total available ventilator beds for each state, sorted by state name.

Note: A state contains multiple cities. Total number of available beds for a respective category (covid or ventilator beds) in a state is the sum of the available beds of all the cities in that state for the respective category(covid or ventilator). Refer testcase output for more clarity.

Create another method with the name get_CiitesWithMoreThanAvgOccupiedbeds, which takes state as argument and returns the dictionary with city as the key and tuple of occupied covid beds and occupied ventilator beds as value, where number of covid beds occupied and ventilator beds occupied are more than the state average for the respective category of beds .

i.e. the City(cities) in the given state to be recorded/resulted( with the data mentioned), should satisfy the below conditions:

Whose occupied covid beds count is more than the "average of Occupied covid beds of all the cities of the given state" and the respective City should also contain the Occupied ventilator beds count more than the "average of occupied ventilator beds of all cities of the given state".

For more clarity , please refer the Sample test case Input and Output in below section

If no city is found with the occupied beds more than state average as mentioned above, then return None and display ‘No city available' (Without quotes) in main function.

Please note that the search operations(if any as per the requirement ..) should be case insensitive.

Instructions to write main function:

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(City and CovBedsAnalysis ) 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 City object after reading the data related to it and add the object to the list of city objects which will be provided to the CovBedsAnalysis object while creation. This point repeats for the number of city objects(considered in the first line of input data) .

ii. Create CovBedsAnalysis object by passing the CovBedsAnalysis name(you can hard-code any name you want) and List of city objects ( created as mentioned in above point# c.i ) as the arguments. d. Take a string value as input depicting the state which is passed to the get_CiitesWithMoreThanAvgOccupiedbeds e. Call the method get_StateWiseAvlblBedStats mentioned above from the main section. f. Display the State,total available covid beds and total available ventilator beds received from the method, with a single space in between as shown in sample testcase output, g. Call the method get_CiitesWithMoreThanAvgOccupiedbeds mentioned above from the main section h. Display the city name, occupied covid beds and occupied ventilator beds with a single space in between as shown in the sample testcase output. I. If None is returned by the method get_CiitesWithMoreThanAvgOccupiedbeds, display the message ‘No city available' (excluding the quotes).

You can use/refer the below given sample input and output to verify your solution using ' Test against Custom Input ' option in Hackerrank.

Input format for Custom Testing:

a.The 1st input taken in the main section is the number of city objects to be added to the list of cities. b.The next set of inputs are the values for the attribtes: city_id,state_name,city_name, covidbeds,avlblcovbeds,ventilbeds,avlblventilbeds respectively for each city taken one after other and is repeated for number of objects given in the first line of testcase input c.The last line of input refers the state name which is passed to the function: get_CiitesWithMoreThanAvgOccupiedbeds

Sample Testcase1:

Input: 5 101 Delhi Delhi 100000 20000 5000 2000 102 Telangana Hyderabad 200000 40000 1000 500 103 Telangana Warangal 100000 30000 2000 1000 104 AndhraPradesh Vijayawada 800000 300000 30000 2500 105 AndhraPradesh Vizag 500000 100000 6000 1000 AndhraPradesh


AndhraPradesh 400000 3500 Delhi 20000 2000 Telangana 70000 1500 Vijayawada 500000 27500

Sample TestCase2:


6 101 Delhi Delhi 100000 20000 8000 3000 102 Telangana Hyderabad 200000 100000 12000 6000 103 Telangana Warangal 100000 50000 1000 500 104 AndhraPradesh Vijayawada 800000 400000 7500 3750 105 AndhraPradesh Vizag 500000 100000 11000 8500 106 Maharashtra Mumbai 1000000 0 12500 0 maharashtra


AndhraPradesh 500000 12250 Delhi 20000 3000 Maharashtra 0 0 Telangana 150000 6500
No city

What I have tried:

During the COVID19 pandemic, the status of beds availability is to be tracked
Updated 5-Jun-22 23:45pm
Richard Deeming 11-Mar-22 3:27am    
Nobody here is going to do your homework for you.

Try it yourself; it will be based on topics you have recently covered in your course.

If you really don't know where to start, then talk to your teacher.
Tejaswini Wakde 16-May-22 6:27am    
SyntaxError: unexpected EOF while parsing
Python 6

Total Marks
Pass Marks
Marks Obtained
Start Time : 18 Dec 2020 09:13 | End Time : 31 Mar 2023 00:00

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer
Satya Narayan Lenka 11-Mar-22 4:20am    
after soe step I don't know to how go forward so plz help me I am college student.
Thank you
OriginalGriff 11-Mar-22 4:31am    
Follow the link at the bottom of my answer - it gives you a method to get from "here" to "there".

You are a student: so learn how to do it! That is why you were set the task - you get you to think about what you have been taught and start learning how to apply that. Just giving you a solution doesn't do that, because it doesn't form the right "mindset" to solve problems.
Sudarshan 2022 6-Jun-22 5:29am    
i have implemented the full solution but it is showing EOF error what to do to rectify the of error
Sudarshan 2022 6-Jun-22 5:48am    
please sent me the full program i need to know where I have done the mistakes in my program for reference please
OriginalGriff 6-Jun-22 6:22am    
So ... you've sat on it for three months, and now the deadline is looming and you haven't done any of it yourself?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900