Need some help...

Boris Borcic bborcic at gmail.com
Tue Oct 30 12:43:09 CET 2007


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



More information about the Python-list mailing list