列表和数组从0开始

列表可以修改,但是元组不能修改

>>> edward=['1',2]
>>> john=['2',3]
>>> database=[edward,john]
>>> database
[['1', 2], ['2', 3]]
>>>

输入年月日,打出相应日期的月份名称

months=['1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
'12']
endings=['st','nd','rd']+17*['th']\
+['st','nd','rd']+7*['th']\
+['st']#endings里面有31个元素,3+17+3+7+1
year=raw_input('Year:')
month=raw_input('Month(1-12):')
day=raw_input('Day(1-31):')
month_number=int(month)
day_number=int(day)
month_name=months[month_number-1]#比如输入1月,则在months里面是第0个元素

ordinal=day+endings[day_number-1]#比如输入1日,则在endings里面是第0个元素,即st

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

posted on 2016-01-10 17:15  薄樱  阅读(155)  评论(0编辑  收藏  举报