In the ISBN-10 (International Standard Book Numbering) system that was used until the end of 2006, each book is assigned a unique 10-digit code. The first nine digits uniquely identify the book itself, whereas the last digit merely serves as a check digit to detect invalid ISBN-10 codes.
If $$x_1, \ldots, x_9$$ represent the first nine digits of an ISBN-10 code, the check digit $$x_{10}$$ is computed as \[x_{10} = (x_1+ 2x_2+ 3x_3+ 4x_4+ 5x_5+ 6x_6+ 7x_7+ 8x_8+ 9x_9)\!\!\!\!\mod{11}\] As a result, the check digit $$x_{10}$$ always takes a value in between 0 and 10. If the check digit is equal to 10, it is represented in the ISBN-10 code by the capital X. As such, only a single character is needed to represent the check digit.
Read a sequence of ISBN-10 codes and determine for each of them whether they correspond to valid ISBN-10 codes. Try to avoid any unnecessary repetition of source code in your solution (code duplication1, DRY2).
A sequence of ISBN-10 codes, each on a separate line. The sequence ends with a line that only contains the word stop.
For each ISBN-10 code from the input, print a single line that either contains the word OK if the given code corresponds to a valid ISBN-10 code or the word WRONG if the given code corresponds to an invalid ISBN-10 code.
Input:
9971502100
9971502108
stop
Output:
OK
WRONG
In the following instruction video, Pythia explains how to tackle this assignment. Watch this video as a stepping stone to solve other exercises about strings3.