Thanks a lot for the help on my last question. I have another problem that I need help with. I need to generate the check digit for an ISBN number. Like if the input is 076372339 the function should return 8.

To find the check digit, which is the last number of the ISBN, you begin by taking the first # and multiplying it by 1, the second number by 2, the third number by 3...through 9. You add all of these numbers. And then the last number (that you don't know) will be (0-10) x 10. That number will be added to the total and then the total is divided by 11. Whichever number (0-10) that leaves no remainder is the correct check digit.

I know how to find it by hand, but I am pretty clueless as to how write a program to do it. My description on how to find it is confusing, I know, but I would appreciate any more help I can get. Meanwhile I will keep messing around with it. Thanks again

Here is the java procedure, not sure if this helps:

public class Mod11Ck {
public static String calc(String digStr) {
int len = digStr.length();
int sum = 0, rem = 0;
int[] digArr = new int[len];
for (int k=1; k<=len; k++) // compute weighted sum
sum += (11 - k) * Character.getNumericValue(digStr.charAt(k - 1));
if ((rem = sum % 11) == 0) return "0";
else if (rem == 1) return "X";
else return (new Integer(11 - rem)).toString();
}
}

Python looks like pseudocode by design, so write down what you would do in pseudocode, and you should be almost there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.