[Tutor] Is there an easily or shorter way?

Ken G. beachkidken at gmail.com
Mon Dec 15 22:25:42 CET 2014


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





More information about the Tutor mailing list