|
| 1 | +import pandas as pd |
| 2 | + |
| 3 | +def getInformation(selectedCountry, rankingFileName, capitalsFileName): |
| 4 | + # add selected country |
| 5 | + # Total number of universities |
| 6 | + # show countries |
| 7 | + # show continents |
| 8 | + # calculate average score (sum of all uni scores within the selected country) / (number of universities within the selected country) |
| 9 | + # display the average score |
| 10 | + # calculate the relative score (average score) / (The highest score within the continent where the university is selected) |
| 11 | + |
| 12 | + available_countries = 0 |
| 13 | + counter = 0 |
| 14 | + countries = "" |
| 15 | + continents = "" |
| 16 | + countries_lst = [] |
| 17 | + continents_lst = [] |
| 18 | + TopUni = pd.read_csv(rankingFileName) |
| 19 | + Capitals = pd.read_csv(capitalsFileName) |
| 20 | + country_counter = 0 |
| 21 | + country_counter_rank = 1 |
| 22 | + |
| 23 | + file = open("output.txt", "w") # open output.txt file where output is stored |
| 24 | + |
| 25 | + for line in range(len(TopUni)): |
| 26 | + counter += 1 |
| 27 | + |
| 28 | + file.write("Total number of Universities => {}\n" .format(counter)) # PART 1 TOTAL NUMBER OF UNIVERSITIES |
| 29 | + |
| 30 | + # LISTING ALL AVAILABLE COUNTRIES WITHIN THE FILE |
| 31 | + for country in Capitals["Country Name"]: |
| 32 | + if country not in countries_lst: |
| 33 | + countries_lst.append(country) |
| 34 | + available_countries += 1 |
| 35 | + |
| 36 | + for country in countries_lst: |
| 37 | + if countries == "": |
| 38 | + countries = countries + country |
| 39 | + else: |
| 40 | + countries = countries + ", " + country |
| 41 | + |
| 42 | + file.write("Available countries => {}\n" .format(countries)) # PART 2 AVAILABLE COUNTRIES |
| 43 | + |
| 44 | + # FINDING ALL AVAILABLE CONTINENTS WITHIN THE FILE |
| 45 | + for continent in Capitals["Continent"]: |
| 46 | + if continent not in continents_lst: |
| 47 | + continents_lst.append(continent) |
| 48 | + |
| 49 | + for continent in continents_lst: |
| 50 | + if continents == "": |
| 51 | + continents = continents + continent |
| 52 | + else: |
| 53 | + continents = continents + ", " + continent |
| 54 | + |
| 55 | + file.write("Available Continents => {}\n" .format(continents)) # PART 3 AVAILABLE CONTINENTS |
| 56 | + |
| 57 | + # FINDING THE INTERNATIONAL RANK OF COUNTRIES ASSOCIATED WITH THE SELECTED COUNTRY |
| 58 | + for country in TopUni["Country"]: |
| 59 | + if country == selectedCountry: |
| 60 | + file.write("At international rank => {} the university name is => {}\n" .format(country_counter_rank, TopUni["Institution name"][country_counter])) # PART 4 INTERNATIONAL RANK |
| 61 | + country_counter += 1 |
| 62 | + country_counter_rank += 1 |
| 63 | + |
| 64 | + country_counter = 0 |
| 65 | + country_national_counter_rank = 1 |
| 66 | + |
| 67 | + for country in TopUni["Country"]: |
| 68 | + if country == selectedCountry: |
| 69 | + file.write("At national rank => {} the university name is => {}\n" .format(country_national_counter_rank, TopUni["Institution name"][country_counter])) # PART 5 NATIONAL RANK |
| 70 | + country_national_counter_rank += 1 |
| 71 | + country_counter += 1 |
| 72 | + |
| 73 | + number_of_universities = 0 |
| 74 | + university_score = 0 |
| 75 | + TopUni = pd.read_csv(rankingFileName) |
| 76 | + counter = 0 |
| 77 | + |
| 78 | + for country in TopUni["Country"]: |
| 79 | + if selectedCountry == country: |
| 80 | + university_score += TopUni["Score"][counter] |
| 81 | + number_of_universities += 1 |
| 82 | + counter += 1 |
| 83 | + |
| 84 | + # THE AVERAGE SCORE CALCULATIONS |
| 85 | + averageScore = university_score / number_of_universities |
| 86 | + file.write("The average score => {}%\n" .format(round(averageScore, 1))) # PART 6 AVERAGE SCORE # PART 6 |
| 87 | + |
| 88 | + number_of_universities = 0 |
| 89 | + university_score = 0 |
| 90 | + TopUni = pd.read_csv(rankingFileName) |
| 91 | + Capitals = pd.read_csv(capitalsFileName) |
| 92 | + highestScore1 = 0 |
| 93 | + highestScore2 = 0 |
| 94 | + highestScore3 = 0 |
| 95 | + highestScore4 = 0 |
| 96 | + highestScore5 = 0 |
| 97 | + counter1 = 0 |
| 98 | + counter2 = 0 |
| 99 | + counter3 = 0 |
| 100 | + continent = "" |
| 101 | + |
| 102 | + # CALCULATING THE RELATIVE SCORE |
| 103 | + for country in TopUni["Country"]: |
| 104 | + if selectedCountry == country: |
| 105 | + university_score += TopUni["Score"][counter1] |
| 106 | + number_of_universities += 1 |
| 107 | + counter1 += 1 |
| 108 | + |
| 109 | + averageScore = university_score / number_of_universities |
| 110 | + |
| 111 | + for country in Capitals["Country Name"]: |
| 112 | + if selectedCountry == country: |
| 113 | + continent = Capitals["Continent"][counter2] |
| 114 | + counter2 += 1 |
| 115 | + |
| 116 | + for continentScore in TopUni["Score"]: |
| 117 | + if TopUni["Country"][counter3] in ["Jordan", "Palestine", "China", "Israel", "Japan", "Singapore", "South Korea", "Taiwan"]: |
| 118 | + if continentScore > highestScore1: |
| 119 | + highestScore1 = continentScore |
| 120 | + elif TopUni["Country"][counter3] in "Australia": |
| 121 | + if continentScore > highestScore2: |
| 122 | + highestScore2 = continentScore |
| 123 | + elif TopUni["Country"][counter3] in ["Canada", "USA"]: |
| 124 | + if continentScore > highestScore3: |
| 125 | + highestScore3 = continentScore |
| 126 | + elif TopUni["Country"][counter3] in ["Denmark", "France", "Germany", "Netherlands", "Norway", "Sweden", "Switzerland", "United Kingdom"]: |
| 127 | + if continentScore > highestScore4: |
| 128 | + highestScore4 = continentScore |
| 129 | + elif TopUni["Country"][counter3] in ["Egypt"]: |
| 130 | + if continentScore > highestScore5: |
| 131 | + highestScore5 = continentScore |
| 132 | + |
| 133 | + counter3 += 1 |
| 134 | + |
| 135 | + # PART 7 RELATIVE SCORE |
| 136 | + if selectedCountry in ["Jordan", "Palestine", "China", "Israel", "Japan", "Singapore", "South Korea", "Taiwan"]: |
| 137 | + relativeScore = (averageScore / highestScore1) * 100 |
| 138 | + file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore1, round(relativeScore, 1))) |
| 139 | + elif selectedCountry in "Australia": |
| 140 | + relativeScore = (averageScore / highestScore2) * 100 |
| 141 | + file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore2, round(relativeScore, 1))) |
| 142 | + elif selectedCountry in ["Canada", "USA"]: |
| 143 | + relativeScore = (averageScore / highestScore3) * 100 |
| 144 | + file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore3, round(relativeScore, 1))) |
| 145 | + elif selectedCountry in ["Denmark", "France", "Germany", "Netherlands", "Norway", "Sweden", "Switzerland", "United Kingdom"]: |
| 146 | + relativeScore = (averageScore / highestScore4) * 100 |
| 147 | + file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore4, round(relativeScore, 1))) |
| 148 | + elif selectedCountry in ["Egypt"]: |
| 149 | + relativeScore = (averageScore / highestScore5) * 100 |
| 150 | + file.write("The relative score to the top university in {} is => ({} / {}) x 100% = {}%\n" .format(continent, averageScore, highestScore5, round(relativeScore, 1))) |
| 151 | + |
| 152 | + # FINDING THE CAPITAL OF THE SELECTED COUNTRY |
| 153 | + Capitals = pd.read_csv(capitalsFileName) |
| 154 | + capital = "" |
| 155 | + counter = 0 |
| 156 | + |
| 157 | + for cap in Capitals["Country Name"]: |
| 158 | + if cap == selectedCountry: |
| 159 | + capital = Capitals["Capital"][counter] |
| 160 | + counter += 1 |
| 161 | + |
| 162 | + file.write("The capital is => {}\n" .format(capital)) # PART 8 CAPITAL OF SELECTED COUNTRY |
| 163 | + |
| 164 | + # FINDING THE UNIVERSITIES THAT HAVE THE NAME OF THE CAPITAL WITHIN IT |
| 165 | + TopUni = pd.read_csv(rankingFileName) |
| 166 | + Capitals = pd.read_csv(capitalsFileName) |
| 167 | + capital = "" |
| 168 | + counter1 = 0 |
| 169 | + counter2 = 0 |
| 170 | + number_counter = 1 |
| 171 | + for cap in Capitals["Country Name"]: |
| 172 | + if cap == selectedCountry: |
| 173 | + capital = Capitals["Capital"][counter1] |
| 174 | + counter1 += 1 |
| 175 | + |
| 176 | + file.write("The universities that contain the capital name => \n") # PART 9 CAPITAL NAME IN UNIVERSITY NAME |
| 177 | + |
| 178 | + for uni in TopUni["Country"]: |
| 179 | + if (selectedCountry == uni) and (capital in TopUni["Institution name"][counter2]): |
| 180 | + file.write("#" + str(number_counter) + " " + TopUni["Institution name"][counter2] + "\n") |
| 181 | + number_counter += 1 |
| 182 | + counter2 += 1 |
| 183 | + |
| 184 | + |
| 185 | +def __main__(): |
| 186 | + country = input("input the country you want to look at: ") |
| 187 | + file1 = "TopUni.csv" |
| 188 | + file2 = "capitals.csv" |
| 189 | + getInformation(country, file1, file2) |
| 190 | + |
| 191 | + |
| 192 | +__main__() |
0 commit comments