Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Aug 22nd, 2004, 7:29 PM   #1
Insomniac
Programmer
 
Insomniac's Avatar
 
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0 Insomniac is on a distinguished road
Here is an example code:

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']

year = raw_input('Year: ')
month = raw_input('Month(1-12): ')
day = raw_input('Day(1-31): ')

month_name = months[int(month)-1]
ordinal = day + endings[int(day)-1]

print month_name + ' ' + ordinal + ', ' + year


Now, this program came out fine due to it being an example in my book.
Even when I went to create my own more simplified version, I did fine.

But, can you explain how Python or the computer for that matter reads where it says 'endings' and is able to properly assign the correct ending for a specific day?

I left this portion out of my personal program because it confused the hell out me and also because the book left this detailed part out.
That's number 1, number 2 is -is 'ordinal' simply a variable or a function because the book didn't say. I tried adding 'ordinal' to my program and it wouldn't accept it.

Please help, Thank you.
__________________
From an IBM Thinkpad T43 - 14.1" SXGA+ - ATI 64 MB X300 - Sonoma 760 - 2 GB RAM - 80 GB HD 5400 - IBM ABG II - FC3, Ubuntu & XPee
DevC++, and Macromedia's - Dreamweaver & Flash Pro and a little Adobe Illustrator & Photoshop
Sleep? Sleep is for the weak.:cool:

Insomniac is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC