External Exam Download Resources Web Applications Games Recycle Bin

Barcode Scanner Algorithm q13 mock

barcode_scanner_algorithm_q13_mock.py

#Stimulus 1: Barcode scanner algorithm

def BarcodeScanner(barcode_string):
      Barcode = list(barcode_string)
      Result = []
      Processed = False
      Valid = True
      Counter = 0
      while not Processed:
            Character = Barcode[Counter]
            if not Character.isdigit() or Counter == 0:
                  if Character == 'T':
                        Result.append('T') #Result[Counter] = 'T'
                  else:
                        Result.append('S') #Result[Counter] = 'S'
                        Valid = True
                  #ENDIF
            else:
                  Result.append(Character) #Result[Counter] = Character
                  Valid = False
                  if Counter == 5:
                        Processed = True
                        Valid = True
                  #ENDIF
            #ENDIF
            Counter = Counter + 1
            #trace values here for question (a):
            print(Character, Result, Valid)
      #ENDWHILE
      return Result
#END

BarcodeScanner("S12345")
BarcodeScanner("T98765")
BarcodeScanner("T12X45")