I saw this was in a earlier post, but I need some addition help with it.

I need help please to write this program. 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 vaules of the letters of the name where 'a' is 1, 'b' is 2, 'c' 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 single name provided as input.

I need something that works off of this...

``````import string
def main():
print"This program calculates the numeric value of a name"
print
message = raw_input("Enter name:")
for ch in message:
lower = string.lower(ch)
num = ord(lower)-96``````

I can't figure out how to add the ords together.

Well, it might be good to stop and analyze the code above. Try inserting a couple of print statements:

``````for ch in message:
print ch
lower = string.lower(ch)
print lower
num = ord(lower) - 96
print num``````

That way you can figure out what's happening in the code. Then, it should be fairly easy to figure out how to add the ords.

Hope it helps,
Jeff

Thanks so much. I just figured it out. I was making it out to be way to complicated than it is. Thanks, again.

Here's was I got...

``````def main():
import string
print"This program calculates the numeric value of a name"
print
message = raw_input("Enter name:")
num=0
for ch in message:

lower = string.lower(ch)

num = ord(lower) - 96 + num
print "The numeric value for that name is", num
main()``````

Congratulations for finding the solution by yourself!

``````def main():
import string``````

This is bad style. Imports should be the first lines in your script.
BTW, you don't need the string-module here. Strings have their lower() method ;)

If you are interested, with the builtin sum() and list comprehension, this can be written as a one-liner (more or less):

``````In [3]: def numify( name ):
...:     return sum( [ ord(char.lower())-96 for char in name ] )
...:

In [4]: numify("Zelle")
Out[4]: 60``````
Be a part of the DaniWeb community

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