Advertisement
Dido09

Brackets

Dec 1st, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. brackets_input = input('put the brackets here: ')
  2. stack_list = []
  3.  
  4. for c in brackets_input:
  5. if len(stack_list) >= 1:
  6. if stack_list[-1] == '(' and c == ')':
  7. stack_list.pop(len(stack_list)-1)
  8. elif stack_list[-1] == '[' and c == ']':
  9. stack_list.pop(len(stack_list)-1)
  10. elif stack_list[-1] == '{' and c == '}':
  11. stack_list.pop(len(stack_list)-1)
  12. else:
  13. stack_list.append(c)
  14. else:
  15. stack_list.append(c)
  16.  
  17. if len(stack_list) == 0:
  18. print('these brackets are correct!')
  19. else:
  20. print('there is a mistake in the brackets...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement