School league with shared ranks
An education ministry publishes a yearly school ranking per subject by pass rate. When schools tie, they must share the same rank, as in a sports competition. Two files are joined by school_id.
scores.csv:student_id,school_id,subject(Math, Science or English),score(0 to 100). A student may miss a subject.schools.csv:school_id,school_name,country
Task: the first input line is a subject, the second an integer min_students. A score of 50 or more is a pass. For each school compute n (scores in that subject) and pass_pct = passes x 100 // n (integer division). Only schools with n >= min_students are ranked. Rank by pass_pct descending using competition ranking: equal pass_pct share a rank and the next rank skips (1, 2, 2, 4). Inside a tie list schools alphabetically by name. Print RANK. School (Country) PCT% of N. If no school qualifies print No schools.
Files your program can read
student_id,school_id,subject,score ST001,SC1,Math,73 ST001,SC1,Science,43 ST001,SC1,English,41 ST002,SC1,Math,29 ST002,SC1,Science,79 ST002,SC1,English,43 ST003,SC1,Math,44 ...
school_id,school_name,country SC1,Ashford Academy,United Kingdom SC2,Colegio Bolivar,Colombia SC3,Lagos Model College,Nigeria SC4,Sakura High,Japan SC5,Maple Ridge Secondary,Canada SC6,Nehru Public School,India SC7,Gymnasium Nord,Germany ...
Open them by name, for example open("scores.csv").
Sample test
Input
Math 8
Expected output
1. Cape Heights School (South Africa) 80% of 10 2. Harbour View College (Australia) 72% of 11 3. Gymnasium Nord (Germany) 60% of 10 4. Maple Ridge Secondary (Canada) 55% of 9 5. Colegio Bolivar (Colombia) 50% of 10 5. Nehru Public School (India) 50% of 10 7. Ashford Academy (United Kingdom) 45% of 11 8. Lagos Model College (Nigeria) 44% of 9 9. Escola Atlantica (Portugal) 40% of 10 10. Sakura High (Japan) 30% of 10
Your answer is also checked against 5 hidden tests.
Need a hint?
Keep the previous pass_pct while walking the sorted list; the rank only changes when the value changes, and it equals the 1-based position.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
