0

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():
    word=raw_input('Enter your name:')
    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

Edited by ~s.o.s~: Added code tags, learn to use them.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by woooee
0

Remember use code tags.
Here a some lines that should help you.

>>> 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.

>>>

Edited by snippsat: n/a

0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.