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:')
    print s
    for l in word:
    print'The numeric value of your name:',sum


any help would be appreciated

Recommended Answers

All 2 Replies

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

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

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