+ 1
Why doesn't this work
The function is supposed to tell whether there are as many x's as o's in the string input, I added the print statements to see what was going on, but I can't tell why it doesn't work. Using an elif for the o line only makes it so nothing is ever added to the o list. Here's the link: https://code.sololearn.com/c0sDlMGt4hVy Thaaaaank you
5 Respuestas
+ 1
You should only change the if ... codition to:
if i == 'x' or i == 'X':
x.append(i)
if i == 'o' or i == 'O':
o.append(i)
And also modify the function call to:
print(XO("ooxXm"))
+ 2
Instead of lists make it a count
x = 0
o = 0
Then instead of appending i,
x += 1 or o += 1
Then just return x == y for true opposite for false
+ 2
Oh well that's one way to do it. I have an obsession with lists lol thanks
0
Lothar's solution actually works. I didn't expect that to happen since == has precedence but ohhhhhhhhh well
EDIT: Why the downvotes? Is there anything specifically wrong with this? I would like to know b/c I thought my original format was good, but when I changed it, the function worked. :/