The most analagous way to do it the way you describe it would be to use two variables left (l) and right (r) that will iterate the string and get their base values using
ord(char) - ord('a') + 1:
my_string = "World" my_string = my_string.lower() l = 0 r = len(my_string)-1 total = 0 while (l < r): total += (ord(my_string[l]) - ord('a') + 1) - (ord(my_string[r]) - ord('a') + 1) r-=1 l+=1 if l == r: total += ord(my_string[l]) - ord('a') + 1 print(total)
However, I would question if this is the best way to approach the problem. Is there a simpler ways to phrase this problem? Also when posting to stack overflow, clearly define you’re problem, what steps you’ve taken, and what your desired output is for the given input.