【发布时间】:2014-09-29 00:35:45
【问题描述】:
#Dancing Text :D
listinput = raw_input("Input text(usually between 1-10 letters ")
dance_time = raw_input("Alternate How Many Times? ")
listinput = list(listinput)
length = len(listinput)
alternate = 0
counter = 0
first_input = listinput
swap_counter = 0
tempchar = ""
counter = int(counter) #Just to make sure...getting errors
#above are just defining variable types and changing types to lists.
while counter <= length:
if alternate == 0: #first, third, fifth character
alternate = alternate + 1
counter = counter + 1
elif alternate == 1: #second, fourth, sixth character and so on....
tempchar = listinput[counter]
tempchar = str(tempchar)
tempchar = tempchar.swapcase()
listinput[counter] = tempchar #It should be the number 1 the first time it runs, but it gives a index error.
alternate = alternate - 1
counter = counter + 1
while swap_counter <= dance_time:
print first_input
print input
swap_counter = swap_counter + 2
这是错误-
第 20 行,在模块中
tempchar = listinput[计数器]
IndexError: 列表索引超出范围
我查找了索引错误,'1'应该在列表的范围内,(我每次测试时都会输入'hello')
如果我理解正确的话,第 20 行,当它运行时应该是“listinput[1]”,变量 'counter' 是 1,因为它只循环了一次。
【问题讨论】: