Problem with a dictionary program....

Ling Lee janimal at mail.trillegaarden.dk
Tue Sep 28 16:36:24 CEST 2004


Thanks Russell Blau, its smart to tjeck for it is really is an integer that 
the user types in :)

I have read the tutorial, but still its a bit hard for me to see how I make 
the loop and how I count the lengt of the number. When I use the len(input) 
I get the reply:  Error len() of unsized object. Think that is why len() 
only works on dictionaries and lists, not strings.

indput = raw_input(" Tell me the number you want to transform to textuel 
representaion")
try:
    indput = str(int(indput))
except ValueError:
    print "No, you need to give me an integer."

This works fine.

But how do i then count the length of the number and make the loop: My goal 
was to:

" I'm trying to write a small program that lets you put in a number as an
integer and then it tells you the textuel representation of the number.

Like if your input is 42, it will say four two.

I found out that I have to make a dictionary like this: List = { 1:"one",
2:"two" and so on )

After I have gotten the lenght of the string, I will write a loop, that goes
through the dictionary as many times as the lengt of the string, and the
gives me the corresponding numbers, the numner 21 would go 2 times through
the loop and give me the output two one.

Sorry to ask this easy questions, but think that things really would make 
sense for me after this little
program is done. I have a lot easier to grasp the magic of pragramming 
through looking at programs than
to read tutorials about it....

Thanks

"Russell Blau" <russblau at hotmail.com> wrote in message 
news:2rt8rsF1ej1qmU1 at uni-berlin.de...
> "Ling Lee" <janimal at mail.trillegaarden.dk> wrote in message
> news:415966e1$0$23075$ba624c82 at nntp05.dk.telia.net...
>>
>> and I have to use the raw_input method to get the number:
>>
>> indput : raw_input(" Tell me the number you want to transform to textuel
>> representaion")
>>
>> The I have to transform the input to a string
>> indput = str(indput)
>
> Actually, the value returned by raw_input() *is* a string, but you might
> want to check to see whether the user has actually typed in an integer as
> opposed to typing, say, "Go away you stupid computer."
>
> try:
>    indput = str(int(indput))
> except ValueError:
>    print "No, you need to give me an integer."
>
>> Will one of you be so kind and tell me how I count the lengt of the 
>> indput
>> number i was thinking on something like input.count[:] but that dosnt
>> work...
>
> You could consider using the built-in function len().
>
>
> -- 
> I don't actually read my hotmail account, but you can replace hotmail with
> excite if you really want to reach me.
>
> 





More information about the Python-list mailing list