Hi, i need some help with a program that calculates the numeric value of a name. The value of a name is determined by summing up the values of the letters of the name where 'a' is 1, 'b' is 2, 'c' is 3 etc., up to 'z' being 26. For example, the name "Zelle" would have the value 26+5+12+12+5=60. Write a program that calculates the numeric value of a complete name such as "John Marvin Zelle". I can get it to work for one name but for a complete name i am lost. Here is my code so far:

``````import string
import math
def main():
sum=0
word=string.upper(word)
s=string.split(word)
print s
for l in word:
sum=sum+ord(l)-64
print'The numeric value of your name:',sum

main()``````

any help would be appreciated

## All 2 Replies

Remember use code tags.

``````>>> s = 'John Marvin Zelle'
>>> l = s.split()
>>> l = ''.join(l)
>>> l
'JohnMarvinZelle'
>>> sum((ord(i)-64 for i in list(l.upper())))
184``````

And dont use sum as variable name,as you se in code over sum() is used by python.

``````>>> help(sum)
Help on built-in function sum in module __builtin__:

sum(...)
sum(sequence[, start]) -> value

Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start' (which defaults to 0).  When the sequence is
empty, returns start.

>>>``````

Or, to state Snippsat's post another way, add another print statement.

``````for l in word:
total=total+ord(l)-64
print l, ord(l)-64, total``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.