I am supposed to write a program that takes a person's whole name and returns the name's numerical value. The numerical value is found by the values of the letters in the name (with a=1, b=2...z=26).

This is what I have so far:

def main ():

    name = input("What is the whole name? ").lower()    #get name, make all lowercase

    alph = [" abcdefghijklmnopqrstuvwxyz"]      #list of characters

    total = 0                                   #apply value for each character in name
    for ch in name:
        total = ord(ch) + total - 96            

    print("The numerical value of the name is \n", total)   #print the result

main()

For some reason my program works with some of the names I input (such as dani = 28), but other names (notably longer ones) are not returning correct answers. What am I doing wrong?

Here is the whole homework problem for reference:

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

Expand your solution to the previous problem to allow the calculation of a complete name such as "Jackson Thomas Mills." The total value is just the sum of the numeric values of all the names.

Recommended Answers

All 3 Replies

Take out the blank at the beginning of alph and ignore all characters not in alph.

A space is not considered a letter so you have to find out a way to skip it.
If you don't succeed in doing that, just return, we will help.

Add a print so you know what is going on and where the problem is occurring.

    for ch in name:
        print("\nbefore", ch, total)
        total = ord(ch) + total - 96            
        print("after", ch, 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, networking, learning, and sharing knowledge.