vim begin2-1-1.py
#根据给定的年月日以数字的形式打印出日期
months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
]
ending = ['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_number = int(month)
day_number = int(day)
month_name = months[month_number-1]
ordinal = day + ending[day_number-1]
print month_name+' '+ordinal+','+year
运行输入如下
PS:本脚本根据用户输入的年月日打印出日期信息,如果输入的月份不在1-12日期不在1-31会报错,但是如果在没有31号月份输入31还是会正常输出