''' CS5001 Fall 2018 Sample code: using a stack as the only data structure, determine whether an input string has balanced parentheses. Definition of balanced: * () is balanced * if x is balanced, then (x) is balanced * if x and y are balanced, then xy is balanced. ''' from mystax import Stack def is_balanced(string): ''' Function is_balanced Input: string (a string) Returns: True if balanced open/close parens, false otherwise ''' stack = Stack() for char in string: if char == "(": stack.push(char) elif char == ")": if stack.is_empty(): return False stack.pop() if stack.is_empty(): return True return False