fork download
  1. #!/usr/bin/python3
  2. import os
  3.  
  4. #charmap = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4,
  5. # 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9}
  6. #multiplier = [9, 8, 7, 6, 5, 4, 3, 2, 1]
  7.  
  8. charmap = {'A': 0, 'D': 1, 'G': 2, 'J': 3, 'C': 4,
  9. 'F': 5, 'I': 6, 'B': 7, 'E': 8, 'H': 9}
  10. multiplier = [3, 6, 9, 2, 5, 8, 1, 4, 7]
  11.  
  12. passed = 0
  13. failed = 0
  14.  
  15. def verify(i):
  16. global passed, failed
  17.  
  18. n = i[0:9]
  19. s = i[9]
  20.  
  21. sum = 0
  22. for c in range(0, 9):
  23. sum += int(n[c])*multiplier[c]
  24.  
  25. if sum%10 == charmap[s]:
  26. result = '\x1B[1;32mPASSED\x1B[m'
  27. passed+=1
  28. else:
  29. result = '\x1B[1;31mFAILED\x1B[m'
  30. failed+=1
  31.  
  32. print("{}{} : {} => {} ... {}".format(n, s, sum, charmap[s], result))
  33.  
  34. if __name__ == '__main__':
  35. with open("charno.txt", "r") as fin:
  36. text = fin.read()
  37.  
  38. x = text.split()
  39.  
  40. for i in x:
  41. verify(i)
  42.  
  43. print("{} passed.\n{} failed.".format(passed, failed))
  44.  
  45. # End of verify.py
Runtime error #stdin #stdout #stderr 0.16s 23572KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 35, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'charno.txt'