Reputation: 141
I feel like I am doing something wrong with the for loop and the user input
Whenever I do the for loop, I do believe that the local variable in the for loop has only one entry in the list
list[index_int] #returns value of the indexed entry in the list
user_input = "1234"
user_input[-1] >>> 4
def print_numbers(n):
for entry in n:
if entry == "1":
if (entry == n[-1]):
print "E"
else:
print entry + "s,",
elif entry == "0":
if (entry == n[-1]):
print "X"
else:
print entry + "X,",
else:
if (entry == n[-1]): #applies if entry is equal to the value of user input at index value of (-1), which I do not want
print entry + "L"
else:
print entry + "s,",
user_input = raw_input()
if user_input.isdigit():
print_numbers(user_input)
else:
print user_input
When I wanted to put down 101 or 212, I get these
Intention -> 1s, X, E
Result:
E
X, E
Intention -> 2s, 1s, 2L
Result:
2L
1s, 2L
I do believe that the cause is that during the for loop, each variable has only one element in its own list.
Is there not a way to check if the for loop is AT the list's (the string's) last index position (NOT having the variable equal to the value of the string's index i.e entry == n[-1])?
Upvotes: 0
Views: 643
Reputation: 799200
You're looking for enumerate()
. And a bit more, but you should be able to figure that part out.
Upvotes: 4