Noob sanitycheck [String comparison] | Sololearn: Learn to code for FREE!


Noob sanitycheck [String comparison]

My testing for string equality within a function is always returning true despite meeting other conditions

1/21/2020 2:39:23 PM


3 Answers

New Answer


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":


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":


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