Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- brackets_input = input('put the brackets here: ')
- stack_list = []
- for c in brackets_input:
- if len(stack_list) >= 1:
- if stack_list[-1] == '(' and c == ')':
- stack_list.pop(len(stack_list)-1)
- elif stack_list[-1] == '[' and c == ']':
- stack_list.pop(len(stack_list)-1)
- elif stack_list[-1] == '{' and c == '}':
- stack_list.pop(len(stack_list)-1)
- else:
- stack_list.append(c)
- else:
- stack_list.append(c)
- if len(stack_list) == 0:
- print('these brackets are correct!')
- else:
- print('there is a mistake in the brackets...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement