string index out of range python
刚开始学习python,敲了书上给的示例:month=['January','Feburay','Match','April','May','June','July','...
刚开始学习python,敲了书上给的示例:
month=['January','Feburay','Match','April','May','June','July','Augest','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=month[month_number-1]
day_name=day+ending[day_number-1]
print month_name+' '+day_name+','+year
提示错误:
Traceback (most recent call last):
File "/Users/apple/Documents/python/date.py", line 8, in <module>
month_name=month[month_number-1]
IndexError: string index out of range
然后在month后面加上s就好了,为什么会这样?求大神指点。
我想我找到问题了,是我不够仔细,没注意相同变量名。 展开
month=['January','Feburay','Match','April','May','June','July','Augest','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=month[month_number-1]
day_name=day+ending[day_number-1]
print month_name+' '+day_name+','+year
提示错误:
Traceback (most recent call last):
File "/Users/apple/Documents/python/date.py", line 8, in <module>
month_name=month[month_number-1]
IndexError: string index out of range
然后在month后面加上s就好了,为什么会这样?求大神指点。
我想我找到问题了,是我不够仔细,没注意相同变量名。 展开
2个回答
展开全部
studen=('xzj','jzx','zxj','jxz'),
这一句中最后的逗号去掉
不去掉的话就相当于studen=(('xzj','jzx','zxj','jxz'),)
这样studen就是含有两个元素的tuple,new_studen[0][3]相当于studen[3],所以就超出范围了
是否可以解决您的问题?
这一句中最后的逗号去掉
不去掉的话就相当于studen=(('xzj','jzx','zxj','jxz'),)
这样studen就是含有两个元素的tuple,new_studen[0][3]相当于studen[3],所以就超出范围了
是否可以解决您的问题?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询