Python新手的一个序列小问题 求大神指导

具体代码如下:

# -*- 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

一直有这个问题,求大神指导。

1个回答

好粗心,逗号没加!

 mouths = [

     "January",

     "February",

     "March",

     "April",

     "May",

     "June",

     "July",

     "August",

     "September",

     "October",

     "November",

     "December",

   ]
qq_21992373
HanawaGuo 回复Kolamu: 哈哈哈哈哈哈哈哈
大约 3 年之前 回复
wangdajiang0711
wangdajiang0711 啊啊 忘记了。。 多谢多谢
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问