FW: Switch statements again

Jeremy Yallop jeremy at jdyallop.freeserve.co.uk
Thu Jan 16 12:38:48 CET 2003


* Dan Bishop
| Why not have optional, explicit fallthru?

It's not needed.  The same thing can be eccomplished in all sorts of
different ways already.

| print "On the %s day of Christmas, my true love gave to me" % ordinal(day)
| switch day:
|    case 12:
|       print "12 drummers drumming,"
|       fall
|    case 11:
|       print "11 pipers piping,"
|       fall
|    case 10:
|       print "10 lords a-leaping,"
|       fall
| # etc.


   gifts = ['12 drummers drumming',
            '11 pipers piping',
            '10 lords a leaping',
            '9 ladies dancing',
            '8 maids a milking',
            '7 swans a swimming',
            '6 geese a laying',
            '5 golden rings',
            '4 calling birds',
            '3 french hens',
            '2 turtle doves and',
            'a partridge in a Pear Tree',]
   
   def sing(day):
       print 'On the %s day of Christmas, my true love gave to me' % ordinal(day)
       for gift in gifts[-day:]:
           print gifts
   
Jeremy.




More information about the Python-list mailing list