How do i assign a numerical value to each uppercase letter, and then use it later via string and then add up the values.
EG.
A = 1, B = 2, C = 3 (etc..)
string = 'ABC'
Then return the answer 6 (in this case).
base = ord('A') - 1
mystring = 'ABC'
print sum(ord(char) - base for char in mystring)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With