0

Noob sanitycheck [String comparison]

My testing for string equality within a function is always returning true despite meeting other conditions https://code.sololearn.com/cc5Qhh0SW7eF/?ref=app

21st Jan 2020, 2:39 PM
ren[paused]
ren[paused] - avatar
3 Answers
+ 3
Your condition is wrong. if "y" or "Y" == sc: This is always True because "y" is evaluated as True (non-empty string). To fix it use another comparison operator like: if "y" == sc or "Y" == sc: or you can simplify like this: if sc in "yY":
21st Jan 2020, 3:09 PM
Tibor Santa
Tibor Santa - avatar
+ 4
if "y" or "Y"== enable_spaces: should be if "y" == enable_spaces or "Y" == enable_spaces: or if you are willing to lowercase before checking, if enable_spaces.lower() == "y":
21st Jan 2020, 3:11 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
I'm starting to see now thank you :) I like some of the option- I guess I forgot to be explicit with the if statement
21st Jan 2020, 3:12 PM
ren[paused]
ren[paused] - avatar