0

4th project of python course of data structure

I have problem in test case 3 and 7 . Can anyone solve it i put my code in comments def balanced(expression): #your code goes here list=[] for i in expression : if i=="(": list.insert(0,i) elif i==")": list.pop(0) if list==[] : return True else: return False print(balanced(input()))

7th Nov 2021, 6:17 AM
Parth Chauhan
Parth Chauhan - avatar
3 Respostas
0
What happens if the input is like this: ( ) ) (. Does your code say true or false. Mine says false. My code has a check that the number of ) is never larger as the number of (. If it happens i return false.
7th Nov 2021, 7:30 AM
Paul
Paul - avatar
0
It return false
7th Nov 2021, 9:51 AM
Parth Chauhan
Parth Chauhan - avatar
0
And this: ( ( ) ) ) ( ( ).
7th Nov 2021, 10:01 AM
Paul
Paul - avatar