Python记:索引操作示例:将以数指定年,月,日的日期打印出来

————————————————————————————————————不要停止奔跑,不要回顾来路,来路无可眷恋,值得期待的只有前方。

months=[
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December'
    ]

endings=['st','nd','rd']+17*['th']\
         +['st','nd','rd']+7*['th']\
         +['st']

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

month_number=int(month)
day_number=int(day)

month_name=months[month_number-1]
ordinal=day+endings[day_number-1]

print(month_name+' '+ordinal+','+year)

 预览:

 

posted @ 2019-07-31 21:27  龙龙666666  阅读(608)  评论(0编辑  收藏  举报