Weekly Challenge #6 – Ranking System

We’re back in action after a lovely half-term holiday.

This is an implementation of a system for ranking players in a particular game. This is based on the ELO system utilised in various one-vs-one games such as chess. Fun fact, this was also found in the 2010 film The Social Network.

It’s a very maths-y challenge, and definitely the hardest one yet. Good luck!


Create a program which asks the user to enter the names of two players. The program should then repeatedly ask which user won each match. After the result of each match has been entered, each player’s win percentage should be output.


Modify your program so that instead of outputting each player’s win percentage, the program now outputs the player’s ranking, using the following formula. (The rating should be a whole number)

NewRating = Pre-Match Rating + 10 * (W – probability)

W is for a win, and for a loss

To calculate the probability of a player winning, use the following formula (Make sure to return a floating point number)

Probability = 1 / (1 + 10 ^ ((Opponent’s Pre-Match Rating – Player’s Pre-Match Rating) / 400))

To begin with, all players will start with an initial rating of 1200.


Extend your program so that it now supports an unlimited number of players. For each player, store a unique user ID along with their rating.