changing numbers to spellings
Tim Williams
tim at tdw.net
Sun Oct 1 18:12:26 EDT 2006
On 1 Oct 2006 14:08:24 -0700, flyingisfun1217 at gmail.com
<flyingisfun1217 at gmail.com> wrote:
> I guess I'm just looking for a small code sample hooked up to the code
> I gave, that would collect the input, compare it to code such as:
>
> if x==5
> print "Five"
> elif x==6
> print "Six"
> elif x==7
> print "Seven"
>
> Something along those lines. That was actually like the code I used for
> something else a while ago.
>
> My only problem is, I want it to be printed to a textvariable for use
> in the label.
You can replace the above snippet with:
my_nums = { 1 : 'One' , 2 : 'Two' , 3 : 'Three' , 4 : 'Four' } # etc etc
print my_nums[x]
so...
>>> x = 2
>>> print my_nums[x]
'Two'
>>> x = 4
>>> print my_nums[x]
'Four'
and my_nums[x] is a "variable" for you to use.
HTH :)
More information about the Python-list
mailing list