dimanche 28 septembre 2014

Indexing error with variables


Vote count:

0





#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


This is the error -


line 20, in module


tempchar = listinput[counter]


IndexError: list index out of range


I looked up indexing errors, and '1' should be in the range of the list, (I enter 'hello' whenever I test it)


If I'm understanding this correctly, the 20th line, when it runs should be "listinput[1]", the variable 'counter' being 1, since it's only looped once.



asked 38 secs ago







Indexing error with variables

Aucun commentaire:

Enregistrer un commentaire