Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 19th, 2012  |  syntax: None  |  size: 0.76 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2.  
  3. def main() :
  4.  
  5.     isbn = [0,0,0,0,0,0,0,0,0,0]
  6.     str1="12-345-67-89x"    
  7.  
  8.    
  9.     str2 = removeH (str1)
  10.  
  11.     print (str2)
  12.    
  13.     toInt (isbn, str2)
  14.    
  15.     for i in range (0, 10):
  16.         print (isbn[i])
  17.    
  18.  
  19. def removeH (str1):
  20.    
  21.         str2 =""
  22.         for i in range (0, len(str1)):
  23.             if ord(str1[i]) != 45:
  24.                 str2 = str2 + str1[i]
  25.         return str2
  26.                
  27.        
  28.  
  29. def toInt (isbn, str1):
  30.  
  31.     for i in range (0, 9):
  32.         c = ord (str1[i])
  33.         if c<48 or c>58:
  34.             return False
  35.  
  36.         isbn[i] = c - 48
  37.        
  38.     if ord(str1[9])==88: # last digit is X
  39.         isbn[9]=10
  40.            
  41.     if ord(str1[9])==120: # last digit is x
  42.         isbn[9]=10
  43.  
  44.     return True