Need some help...

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sun Oct 28 07:56:47 EDT 2007


> 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




More information about the Python-list mailing list