I am having a problem with my list in python.
I am printing out the list (working), a number that shows the line number (working) and an item in the list that should change every time the list is printed(not working?)
a = ["A", "B", "C", "D", "E"]
b = 0
for x in a:
while b <= 10:
print(a, x, b)
b += 1
My current program output is
['A', 'B', 'C', 'D', 'E'] A 0
['A', 'B', 'C', 'D', 'E'] A 1
['A', 'B', 'C', 'D', 'E'] A 2
['A', 'B', 'C', 'D', 'E'] A 3
so on
the output I would like
['A', 'B', 'C', 'D', 'E'] A 0
['A', 'B', 'C', 'D', 'E'] B 1
['A', 'B', 'C', 'D', 'E'] C 2
['A', 'B', 'C', 'D', 'E'] D 3
and so on Although, when I try a different program it works perfectly?
list = ["a", "b", "c"]
for a in list:
print(a)
Why does this happen and how can I fix it?
for/whileloop is not correctly indented. so it is hard to see what's wrong there.printor theprintand theb +=…in both cases the output is not what you mentioned.