Need some help...

Boris Borcic bborcic at gmail.com
Fri Nov 2 11:57:57 CET 2007


Ricardo Aráoz wrote:
 > Boris Borcic wrote:
 >> Ricardo Aráoz wrote:
 >>> Boris Borcic wrote:
 >>>> hyozan.ux3 at gmail.com wrote:
 >>>>> I want to create a program that I type in a word.
 >>>>>
 >>>>> for example...
 >>>>>
 >>>>> chaos
 >>>>>
 >>>>> each letter equals a number....
 >>>>>
 >>>>> A=1
 >>>>> B=20
 >>>>>
 >>>>>  and so on.
 >>>>>
 >>>>> So Chaos would be
 >>>>>
 >>>>> C=13 H=4 A=1 O=7 S=5
 >>>>>
 >>>>> I want to then have those numbers
 >>>>> 13+4+1+7+5 added together to be 30.
 >>>>>
 >>>>> How can I do that?
 >>>>>
 >>>>> Also, just curious, but, how could I then have the 3 and 0 added
 >>>>> together to be 3?
 >>>>>
 >>>>> Please help me out.
 >>>>>
 >>>>> Thank you.....
 >>>>>
 >>>>  >>> sum(dict(C=13,H=4,A=1,O=7,S=5)[_] for _ in 'CHAOS')
 >>>> 30
 >>>>  >>> sum(eval(ch) for ch in str(_))
 >>>> 3
 >>>>>> def sumToOneDigit(num) :
 >>> 	if num < 10 :
 >>> 		return num
 >>> 	else :
 >>> 		return sumToOneDigit(sum(int(i) for i in str(num)))
 >>>
 >>> 	
 >>>>>> sumToOneDigit(sum(ord(ch) for ch in 'chaos'.upper()))
 >>> 6
 >>>
 >>>
 >>>
 >>> HTH
 >> HTH what ?
 >
 >
 > HTH : Hope that helps
 >
 > Citing your post :

Not me, the OP "hyozan.ux3 at gmail.com".

 > """
 > Also, just curious, but, how could I then have the 3 and 0 added
 > together to be 3?
 > """
 >
 > you have the function "sumToOneDigit" that adds the digits of a number
 > till you get one digit (isn't that what you where curious about?)

I had provided a solution that conformed to the OP's 2 questions. Your 
non-conform addition simply proved that you hadn't bothered to read.

Or else you meant to read the OP's mind beyond what he specified; but then you 
should adress him, not me.

 >
 > And answering the main question : sum(ord(ch) for ch in 'chaos'.upper())
 > which is inside the "sumToOneDigit" funtion in my answer.

No, you did not adress the original questions.

My "hth what ?" was an invitation to
rectify. Sorry it wasn't enough for you, but the verbosity was probably worth
what you paid for it.

 >
 > Sorry if that is not enough for you, but the answer is probably worth
 > what you paid for it.
 >
 >
 >




More information about the Python-list mailing list