Second Saturday

Second Saturday Code In Python
My daughter loves Second Saturdays of the month. Every Saturday, when she is getting ready for school, she asks “When is the next second Saturday?”. Her school’s off on second saturday.

So to relieve myself of hunting for a calendar every time, wrote a little program that gives all the second saturdays for a given year.

Posting it here, just in case someone else need it.


import calendar
def GetSecondSaturday(year):
    months=["January","February","March","April","May","June","July","August","September","October","November","December"]
    print '%10s: %4s' % ("Month","Day")
    for month in range(12):
	c = calendar.monthcalendar(year,month+1)
 	fw=c[0]
 	sw=c[1]
 	tw=c[2]
 	if fw[calendar.SATURDAY]:
 	   md=sw[calendar.SATURDAY]
 	else:
 	   md=tw[calendar.SATURDAY]
        print '%10s: %4s' % (months[month],md)


GetSecondSaturday(2014)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s