Calculate number of X and O

# Check to see if a string has the same amount of 'x's and 'o's. # The method must return a boolean and be case insensitive. The string can contain any char. def xo(s): s = s.lower() if s.count('x') != s.count('o'): return False elif s.count('x') < 0 or s.count('o') < 0: return True elif s.count('x') == s.count('o'): return True # XO("ooxx") => true # XO("xooxx") => false # XO("ooxXm") => true # XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true # XO("zzoo") => false

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.