INLAB 4

INLAB 4
Q.A team of experts formed by Govt. of India conducted a survey on colleges in India. Let us assume that the survey was conducted in ‘n’ number of institutes. The experts were asked to rank the institutes based on three different metrics. The metrics are facilities, academics and infrastructure. Maximum score in each category is as follows.
Facilities = 25
Academics = 50
Infrastructure = 25
At the end of the survey the scores of the individual metrics are added up to get the total score and the institutes are ranked based on the total score. The institute that scores the highest score is ranked 1st. Next highest score is given the rank 2 and so on. Write a program to read the scores of the three metrics for each institute, store the scores in a list. Make a list of individual score list for 10 institutes. Print only the Total score in the sorted (Descending) order. Use insertion sort for arranging the data in descending order.
number_institutes = int(input())
facility_scores = []
academics_scores = []
infra_scores = []
total_scores = []
flag = True
for i in range(number_institutes):
    facility_s = int(input())
    acad_s = int(input())
    infra_s = int(input())
    if facility_s >= 0 and facility_s <= 25 and acad_s >= 0 and acad_s <= 50 and  infra_s >= 0 and infra_s <= 25:
        facility_scores.append(facility_s)
        academics_scores.append(acad_s)
        infra_scores.append(infra_s)
        total_scores.append(facility_s + acad_s + infra_s)
    else:
        flag = False
if flag == True:
    total_scores.sort(reverse=True)
    print(total_scores)
else:
    print('Invalid Input')

Comment:
The teacher told us not to program code for insertion sort and rather use the sort function

Algorithm
Step1. Get the number of institutes
Step2. Repeat until i is less than number of institutes
Step2.1 Get Facilities scores
Step2.2 Get Academics scores
Step2.3 Get Infrastructure scores
Step3. Insert the scores in separate lists according to the category
Step4. Process the list of total scores
Step5. Sort the list of total scores using insertion sort
Step6. Reverse the above list and print it.

No comments:

Post a Comment

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...