fork download
  1. print """
  2. Welcome to the ISBN checker,
  3.  
  4. To use this program you will enter a 10 digit number to be converted to an International Standard Book Number
  5.  
  6. """
  7.  
  8. ISBNNo = raw_input("please enter a ten digit number of choice")
  9.  
  10. assert len(ISBNNo) == 10
  11.  
  12. counter = 11 #Set the counter to 11 as we multiply by 11 first
  13. acc = 0 #Set the accumulator to 0
  14.  
  15. for i in ISBNNo[0:9]:
  16. print str(i) + " * " + str(counter)
  17. acc = acc + (int(i) * counter) #cast value a integer and multiply by counter
  18. counter -= 1 #decrement counter
  19. print "Total = " + str(acc)
  20.  
  21. # Mod by 11 (divide and take remainder
  22.  
  23. acc = acc % 11
  24. print "Mod by 11 = " + str(acc)
  25.  
  26. # take it from 11
  27.  
  28. acc = 11 - acc
  29. print "subtract the remainder from 9 = " + str(acc)
  30.  
  31. # concatenate with string
  32.  
  33. ISBNNo = ISBNNo + (str(acc) if acc < 10 else 'X')
  34. print "ISBN Number including check digit is: " + ISBNNo
Success #stdin #stdout 0.08s 8696KB
stdin
0306406152
stdout
Welcome to the ISBN checker,

To use this program you will enter a 10 digit number to be converted to an International Standard Book Number


please enter a ten digit number of choice0 * 11
3 * 10
0 * 9
6 * 8
4 * 7
0 * 6
6 * 5
1 * 4
5 * 3
Total = 155
Mod by 11 = 1
subtract the remainder from 9 = 10
ISBN Number including check digit is: 0306406152X