Learn

Kenny’s first job out of college is teaching high-school algebra. It’s a normal day in school and Kenny needs to break the class up into pairs for a project. Sounds easy enough, but Kenny wants to match the students who are struggling with those who understand the material.

Kenny looks at the problem and thinks to himself, “You know what? I’ll use an algorithm to pair up these students!”

Kenny quickly writes up his class roster using the Python programming language and writes a program that pairs the highest scoring student with the lowest scoring student, the second highest scoring student with the second lowest scoring student, and so on.

What does that mean?

An algorithm is a step-by-step solution to a general type of problem. To solve this student-pairing problem, Kenny needs to write a sorting algorithm.

Instructions

1.

In the editor, you’ll find the code for Kenny’s algorithm, as well as a list of all the students in his class. Copy paste the code below into the bottom of script.py and click run to see how his class is sorted into pairs by the algorithm.

kennys_algorithm(student_grades)

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?