具体代码如下:
# -*- coding: UTF-8 -*-
#根据给定的年月日打印出响应的日期
mouths = [
"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 = raw_input("Year: ")
mouth = raw_input("Mouth(1-12): ")
day = raw_input("Day(1-31): ")
mouth_number = int(mouth)
day_number = int(day)
mouth_name = mouths[mouth_number-1]
ordinal = day + endings[day_number-1]
print mouth_name+' '+ordinal+','+year
个人感觉代码应该没问题,但是在运行这个程序的时候
============= RESTART: C:/Python27/My Python Programs/suoyin.py =============
Year: 1997
Mouth(1-12): 3
Day(1-31): 5
Traceback (most recent call last):
File "C:/Python27/My Python Programs/suoyin.py", line 34, in
mouth_name = mouths[mouth_number-1]
IndexError: list index out of range
一直有这个问题,求大神指导。