[Tutor] numbers from a name
Goofball223@wmconnect.com
Goofball223 at wmconnect.com
Sun Sep 25 05:50:24 CEST 2005
Hello
with the following program I would like it to be able to take a person's name
and then assign values to each letter and come up with a sum of all the
letters in the name. for example if I entered bob. i would like the program to be
able to print bob and then print the total of bob which would be 2 + 15 + 2 =
18.
import string
def main():
value = (raw_input("Please enter your first name"))
table = {'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5, 'f' : 6, 'g' : 7,
'h' : 8, 'i' : 9, 'j' : 10, 'k' : 11, 'l' : 12, 'm' : 13, 'n' : 14, 'o' : 15,
'p' : 16, 'q' : 17, 'r' : 18, 's' : 19, 't' : 20, 'u' : 21, 'v' : 22,
'w' : 23, 'x' : 24, 'y' : 25, 'z' : 26}
total = 0
name = list(name)
for string in name:
total += table[string.lower()]
print "The total of your name is:", total
main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050924/9fa01899/attachment.html
More information about the Tutor
mailing list