+ 2

Program stuck in infinite loop

i wrote a bracket checker program in Python and I don't know why it sticks on an infinite loop. I couldn't find an infinite loop in my code. Please don't send a code for bracket checker, only highlight my own codes bug. this is my code: ------------------------------------------------------------------------------------------------------------ string=input("input the phrase you wanna check: ") chars_collector=[] for character in string: chars_collector.append(character) while chars_collector: passed=False for i in range (len(chars_collector)-1): if chars_collector[i]==chars_collector[i+1]: chars_collector[i],chars_collector[i+1]=0,0 passed=True elif passed==False : for zeros in chars_collector: chars_collector=[zeros.pop for zeros in chars_collector if zeros==0] print(chars_collector) break -------------------------------------------------------------------------------------------------------------- ill appreciate if you answer.

28th Feb 2019, 9:12 AM
alireza
alireza - avatar
5 odpowiedzi
+ 2
It returns IndexError in line 9: "if chars_collector[i]==chars_collector[i+1]:" Can you give an input example?
28th Feb 2019, 9:34 AM
Pedro Tortello
Pedro Tortello - avatar
+ 1
My code have many wrongs tnx for trying to help me i think i should rewrite it.
1st Mar 2019, 6:48 PM
alireza
alireza - avatar
0
for example you give "(())" as input and it says whether it is matched or unmatched. and about the index error i debug it for many times but i didnt get that.
28th Feb 2019, 1:48 PM
alireza
alireza - avatar