Help with Edabit challenge

The challenge is to write a code that counts the number of X’s and O’s in a string, and if they are equal then it should return True and if they are not then it should return False. The code should also return True if there are no X’s and O’s. Below is the code I tried:

def XO(txt): number_of_Xs = 0 number_of_Ohs = 0 for letter in txt: if letter == 'X' or 'x': number_of_Ohs += 1 continue for letter in txt: if letter == 'O' or 'o': number_of_Xs += 1 continue if number_of_Xs == number_of_Ohs: return True if number_of_Xs != number_of_Ohs: return False else: return True XO('OOXx')

Could someone identify what is wrong with my code? I’m trying to use only what I have learned so far. Thanks in advance!

if letter == 'X' or 'x' always evaluates to true even if the letter is a W or a @, Can you see why?

Does it have anything to do with the parameter of the function not being a string value?

@toastedpitabread is trying to hint you that the statement is incorrect.

Your condition statements won’t be able to execute hence the resulting output will be equals to True. Unfortunately.

What happens with the conditional statement is whenever you have an and or orclause you need to fully state what you’re evaluating, it has no way of remembering your old value.

Moreover, it is completely valid to test a conditional like this

#code, there exists a variable foo
if foo:
  #do this

In the above example, foo doesn’t have to be a boolean, it could just be a string or an integer, and if it’s None or 0 or '' it will evaluate to false, otherwise true.

So that’s why when you write:

if `x`:

that part of the clause always evaluates to true.

Therefore you’re virtually writing

if condition or True:

which always evaluates to true.