months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
#1-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_number = int(month)
day_number = int(day)
month_name = months[ month_number - 1 ]
ordinal = day + endings[ day_number - 1 ]
print month_name + ' ' + ordinal + ', ' + year
raw_input()
第1个回答 推荐于2016-07-10
我试了一下,也是秒退。
在命令行里运行,发现输出说是有不可识别的字符,那肯定是其中的中文字了。
要么把那行中文注释删掉,要么在最开始加上
# coding=gbk本回答被提问者和网友采纳
在命令行里运行,发现输出说是有不可识别的字符,那肯定是其中的中文字了。
要么把那行中文注释删掉,要么在最开始加上
# coding=gbk本回答被提问者和网友采纳
第2个回答 2012-09-19
months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
#1-31数字的结尾
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)
input()
在3.2版本我试了一下,没有闪退现象
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
#1-31数字的结尾
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)
input()
在3.2版本我试了一下,没有闪退现象