Thread: List Question
View Single Post
Old Aug 23rd, 2004, 1:58 AM   #2
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 707
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Alright, well let's take a look at the structures in this program.

What we have are two list. months and endings.

Now what we need to remember is that when we have a list, to call an item off the list we have to call it with an offset of one because the first item starts at 0 instead of 1.

e.g.
list = ['dog','cat','mouse','bird']
print list[1]
print list[0]
print list[3]
print list[2]
wourld weild the results

cat
dog
mouse
bird


With that in mind, this is what months look like.


Jan 0, Feb 1, Mar 2, Apr 3, May 4, Jun 5, Jul 6, Aug 7, Sept 8, Oct 9, Noc 10, Dec11


Ok, assuming that the user has already entered the date into the raw_inputs, let's take this apart and see how it works.

month_name = months[int(month)-1]

What that is doing is first turning your answere which is a string into an interger, and then making a call back to the list month with that interger minus one. So in reality it looks like this.

If use choose 7 (july) as your month it turns 7 into an interger and then subtracts one, because if it didn't it would choose August.

That should clear up how it pics the month. Now for the fun part, the ending

Let's look at your list endings.
endings = ['st', 'nd', 'rd'] +17 * ['th']\
+ ['st', 'nd', 'rd'] +7 * ['th']\
+ ['st']

What that looks like without the +17 * ['th] and +7 * ['th'] is

['st', 'nd', 'rd','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th',st', 'nd', 'rd','th','th','th','th','th','th','th','st']


And when you see it expanded like that, it works the same as what happens when you call months. It takes a number, changes it to an interger, then subtracts one.

And for your second question ordinal is just a variable.

That wasn't to clear, but I hope if sheds some light. Feel free to ask more questions if need be. How that helps ya out!
thechristelegacy is offline   Reply With Quote