Numerologists claim to be able to determine a person's character traits based on the "numeric value" of a name. The value of a name is determined by summing up the values of the letters of the name. For example, the name Zelle would have the value 26 + 5 + 12 + 12 + 5 = 60. Write a function called get_numeric_value
that takes a sequence of characters (a string) as a parameter. It should return the numeric value of that string. You can use to_numerical
in your solution.
First, my code for to_numerical
(a function I had to make to convert letters to numbers [notably not the ASCII codes; had to start from A = 1, etc.]) was this:
def to_numerical(character):
if character.isupper():
return ord(character) - 64
elif character.islower():
return ord(character) - 96
In regards to the actual problem, I'm stuck since I can only get the function to return the value of the Z in Zelle. I've pasted what I have so far below:
def get_numeric_value(string):
numerals = []
for character in string:
if character.isupper():
return ord(character) - 64
elif character.islower():
return ord(character) - 96
return numerals
addition = sum(numerals)
return addition
How can I get it so the code will add up and return all the letters? I've been trying to think something up for an hour but I'm stumped.