On 15 December 2014 at 21:25, Ken G. <beachkid...@gmail.com> wrote:
> I am sure there is a better way to refine the following lines.
>
> Letting x equal a number from 1 to 28, go through 28 separate 'if'
> statements to print a resulting value that equaled the value of x.
>
> For example:
>
> x = 8
>
> if x = 1, print 'one'
> if x = 2, print 'two'
> ...
> ...
> if x = 8, print 'eight'
> ...
> ...
> if x = 28, print 'twenty eight'
>
> Would a single line using list or dictionary be shorter?
>
> Thanks,
>
> Ken
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


If you wanted to do this without additional libraries, consider how
many *unique* words are actually required if you were to write them
all out. You could use a dictionary to map the numbers to their words

-- Bodsda
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to