id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

is_balanced


Write a function, is_balanced, that will return True if its input is a string that has balanced parentheses. "Balanced" means that the string has the same number of left parentheses, "(", and right parentheses, ")". But furthermore, they must come in pairs, "(" matched to a following ")", so that "()" is balanced, but ")(" is not. The string may contain any number of non-parenthesis characters; those don't matter.


is_balanced('()') → True
is_balanced(')(') → False
is_balanced('((x+1) * (x-1))') → True

...Save, Compile, Run (ctrl-enter)

def is_balanced(text):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Copyright Nick Parlante 2017 - privacy