+ 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

4th May 2020, 3:36 AM
Sherlyn A.
Sherlyn A. - avatar
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"))
4th May 2020, 11:39 AM
Lothar
Lothar - avatar
+ 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
4th May 2020, 3:47 AM
Slick
Slick - avatar
+ 2
Oh well that's one way to do it. I have an obsession with lists lol thanks
4th May 2020, 4:00 AM
Sherlyn A.
Sherlyn A. - avatar
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. :/
4th May 2020, 2:06 PM
Sherlyn A.
Sherlyn A. - avatar