I recently bought a book on Python, and I'm working my way through it. However, I've come to a very simple program, but I can't understand a certain part of the code. Can someone explain?
# 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 = + 17 * \
+ + 7 * \
+year = raw_input('Year: ')
month = raw_input('Month (1-12): ')
day = raw_input('Day (1-31): ')
month_number = int(month)
day_number = int(day)# Remember to subtract 1 from month and day to get a correct index
month_name = months[month_number-1]
ordinal = day + endings[day_number-1]
print month_name + ' ' + ordinal + ', ' + year
OK, pretty simple. But here's the part that confuses me.
# A list with one ending for each number from 1 to 31
endings = + 17 * \
+ + 7 * \
+
Ok, I understand what it does. I just don't understand why. It just adds the ending to the month. September 11th, etc. But what's with the + 17 multiplied by 'th' -- + 7 multiplied by 'th'? This is really driving me nuts, and I know the answer is right in front of me, which makes it even worse. Not just the + 17 * -- + 7 * , but the whole thing. Can someone please explain how and why this code works?
Thanks in advance, everyone. I'd be lost without you guys.