I need to create a function that takes a 13 digit sequence and uses the last number as a check using modulo 10. ie BAF189D234EA2 entry check = 2.
Using the values of A-F (see weight dict below) instead of ord(char). So as my loop iterates I need char to pull the corresponding weight dict if it is a string value. I simply cannot figure out how to make it call from that dictionary based on the value of char.
Thanks in advance for any help.
weight={
'A' : '10',
'B' : '11',
'C' : '12',
'D' : '13',
'E' : '14',
'F' : '15',
}
def validater(value):
global userEntry
valSum = 0
i = 0
for char in userEntry:
if i == 12:
break
try:
if char >=0 and char <= 9:
valSum += char * i
i +=1
except TypeError:
valSum += weight[char] * i
i += 1
Error:
Traceback (most recent call last):
line 93, in <module>
if validater(userEntry) ==True:
line 74, in validater
valSum += weight[char] * i
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
Edit: Thanks, I changed the dictionary by dropping the quotes around my ints. Now I get a Key Error 1