Mega Code Archive

 
Categories / Python Tutorial / List
 

Print out a date, given year, month, and day as numbers

months = [     'January',     'February',     'March',     'April',     'May',     'June',     'July',     'August',     'September',     'October',     'November',     'December' ] # A list with one ending for each number from 1 to 31 endings = ['st', 'nd', 'rd'] + 17 * ['th'] \         + ['st', 'nd', 'rd'] +  7 * ['th'] \         + ['st'] month_number = 8 day_number = 1 month_name = months[month_number-1] ordinal = endings[day_number-1] print month_name  print ordinal