代码如下
刚开始学python…可能描述的不清楚…
months = [
'January'
'February'
'March'
'April'
'may'
'June'
'July'
'September'
'August'
'October'
'November'
'December'
]
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_number = int(month)
day_nubmber = int(day)
month_name = months[month_number-1]
ordinal = day + endings[day_number-1]
print month_name + ' ' + ordinal + ',' + year
----------------分割线----------------
回@lohocla4dam
我修改以后是这样的……NameError: name 'day_number' is not defined
代码如下
months = [
'January',
'February',
'March',
'April',
'may',
'June',
'July',
'September',
'August',
'October',
'November',
'December'
]
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_number = int(month)
day_nubmber = int(day)
month_name = months[month_number-1]
ordinal = day + endings[day_number-1]
print month_name + ' ' + ordinal + ',' + year
你没有发现你给
months
赋值的时候少写了逗号吗。。。题主试试这段代码就明白了