#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
이 오류이며 색인 생성 오류를 찾았으며 '1'은 목록의 범위에 있어야합니다. (테스트 할 때마다 'hello'를 입력합니다)인덱싱 오류
올바르게 이해한다면 20 번 줄은 "listinput [1]"이어야하고, 변수 'counter'는 1 번만 실행되므로 1 번만 실행해야합니다.
당신을 감사합니다! 색인 생성이 0에서 시작되었음을 알고 있었지만 <= 기호를 수행하는 동안이를 고려하지 않았습니다. 많이 감사합니다 –