Author: Not specified Language: text
Description: Not specified Timestamp: 2017-08-03 21:22:18 +0000
View raw paste Reply
  1. #!py
  2. string1 = 'A      B         C'
  3. string2 = 'D      E         F'
  4. string3 = 'THIS   THAT     THEN'
  5.  
  6. global_char1 = 'Undefined'
  7. global_space1 = 'Undefined'
  8. global_char2 = 'Undefined'
  9. global_space2 = 'Undefined'
  10. global_char3 = 'Undefined'
  11.  
  12. for string in string1, string2, string3:
  13.   column = 0
  14.   while True:
  15.     if string[column] != ' ':
  16.       char1 = column
  17.       print "First char found at " + str(column) + ' = ' + string[column]
  18.       if global_char1 == 'Undefined':
  19.         global_char1 = char1
  20.         print "Defined comparison_char1 as " + str(global_char1)
  21.       elif char1 != global_char1:
  22.           print "Columns don't match in string " + str(string) + " for column 1. Expected column 1 to be at " + str(global_char1)
  23.           exit(2)
  24.       break
  25.     column += 1
  26.  
  27.   while True:
  28.     if string[column] == ' ':
  29.       break
  30.     column += 1
  31.  
  32.   while True:
  33.     if string[column] != ' ':
  34.       char2 = column
  35.       print "Second char found at " + str(column) + ' = ' + string[column]
  36.       if global_char2 == 'Undefined':
  37.         global_char2 = char2
  38.         print "Defined comparison_char2 as " + str(global_char2)
  39.       elif char2 != global_char2:
  40.           print "Columns don't match in string " + str(string) + " for column 2. Expected column 2 to be at " + str(global_space2)
  41.           exit(2)
  42.       break
  43.     column += 1
  44.  
  45.   while True:
  46.     if string[column] == ' ':
  47.       break
  48.     column += 1
  49.  
  50.   while True:
  51.     if string[column] != ' ':
  52.       char3 = column
  53.       print "Third char found at " + str(column) + ' = ' + string[column]
  54.       if global_char3 == 'Undefined':
  55.         global_char3 = char3
  56.         print "Defined comparison_char3 as " + str(global_char3)
  57.       elif char3 != global_char3:
  58.           print "Columns don't match in string " + str(string) + " for column 3. Expected column 3 to be at " + str(global_char3)
  59.           exit(2)
  60.       break
  61.     column += 1
  62.  
  63.  
  64.   $  python columns.py
  65. First char found at 0 = A
  66. Defined comparison_char1 as 0
  67. Second char found at 7 = B
  68. Defined comparison_char2 as 7
  69. Third char found at 17 = C
  70. Defined comparison_char3 as 17
  71. First char found at 0 = D
  72. Second char found at 7 = E
  73. Third char found at 17 = F
  74. First char found at 0 = T
  75. Second char found at 7 = T
  76. Third char found at 16 = T
  77. Columns don't match in string THIS   THAT     THEN for column 3. Expected column 3 to be at 17
  78.  
View raw paste Reply