Need some help...

martyw nomail at noserve
Sun Oct 28 08:12:46 EDT 2007


bearophileHUGS at lycos.com wrote:
>> I want to create a program that I type in a word.
> 
> You can see that Python has a command to input strings from the
> command line.
> 
>> 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?
> 
> Python has a dictionary data structure called dict(), or {}, that you
> can use to map your letters to those numbers. With it you can created
> the letter-number association.
> 
> Then you can scan the characters of the input string one after the
> other, and sum their values into a single total value. Try writing
> that code, and then show it to us, we can give more suggestions if you
> need them...
> 
> Bye,
> bearophile
> 
as an alternative for the suggest dictionary approach you could study 
the built in functions ord() and chr(), see the documentation 
(http://docs.python.org/lib/built-in-funcs.html)



More information about the Python-list mailing list