""" ants3.py classic counting song further improvement with a list """ distraction = [ "", "suck his thumb", "tie his shoe", "climb a tree" ] def chorus(): output = """ ...and they all go marching down- to the ground- to get out- of the rain. Boom boom boom boom boom boom boom """ return output def verse(verseNum): problem = distraction[verseNum] output = """ The ants go marching %(verseNum)d by %(verseNum)d hurrah, hurrah! The ants go marching %(verseNum)d by %(verseNum)d hurrah, hurrah! The ants go marching %(verseNum)d by %(verseNum)d, The little one stops to %(problem)s """ % vars() return output for verseNum in range(1, len(distraction)): print verse(verseNum) print chorus()