![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Aug 2004
Location: Cloud #9
Posts: 47
Rep Power: 0
![]() |
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: |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|