Allan [EMAIL PROTECTED] wrote:
as so forth. I then input a name. How do I treat each letter as a
single value? That is, instead of print myname I have to do a print
m+y+n+a+m+e which returns a number. I next want to convert the
resulting two or three digit number to a single digit. Like 123 would
I'm trying to write a numerology program where I have each letter
identified by a numerical value like
a=1
b=2
c=3
as so forth. I then input a name. How do I treat each letter as a
single value? That is, instead of print myname I have to do a print
m+y+n+a+m+e which returns a number. I next want
AllanI hope this isn't too stupid of a question.
It's a simple problem, but it's not a stupid question, this is a
possible solution:
data = myname
radix = str(sum(ord(c)-96 for c in data))
while len(radix) 1:
radix = str(sum(int(c) for c in radix))
print The radix of:\n, data, \n\nIs:\n,
On Mon, 27 Feb 2006 02:31:42 -0800, Allan wrote:
I'm trying to write a numerology program where I have each letter
identified by a numerical value like
a=1
b=2
c=3
as so forth. I then input a name. How do I treat each letter as a
single value? That is, instead of print myname I have to do
Sounds like homework to me.
Sorry Steven, you may be right, next time I'll be more careful.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Your tools are:
1. map lets you apply a function to every element of a list.
Strings are lists. (List comprehensions let you do the same thing, but
map is better to use if you are turning in homework).
2. sum lets you calculate the sum of all numbers in a list.
3. val and str let you turn