You can convert the string to lowercase with lower function and iterate through the characters in the word, with a for loop, like this
def special_hash(word, tablesize):
for char in word.lower():
...
Then, you can get the character code corresponding to the character with ord function.
def special_hash(word, tablesize):
total_value = 0
for char in word.lower():
total_value += ord(char) - ord('a') + 1
Since we need to get the offset of the character in the alphabets, you can subtract the first value from the current value. Then finally, you can use modulo operator % to get the remainder of the division by tablesize
def special_hash(word, tablesize):
total_value = 0
for char in word.lower():
total_value += ord(char) - ord('a') + 1
return total_value % tablesize
The same can be written succintly with a generator expression and built-in sum function, like this
def special_hash(word, tablesize):
return sum(ord(char) - ord('a') + 1 for char in word.lower()) % tablesize
tablesize?13.tablesizeis 13 only I guess