Why Does This While Loop Not Work?
This loop keeps looping even if I enter 'no' and when I type 'jdlfjap', for example, it continues to loop without a '?'. Does anyone know why this is? def makeContact(): contac
Solution 1:
The statement if continueMaking == "Yes" or "yes" or "YES":
is equivalent to (continueMaking == "Yes") or "yes" or "YES":
which, regardless of the value of continueMaking
returns the string "YES"
, which is truthy and thus the makeContact
call always executes. Case-insensitive string comparisons can be accomplished by continueMaking.lower() == "yes"
.
Solution 2:
Overwriting the function continueMaking
with the variable continueMaking
adds confusion. Choose a different variable name. Readability counts.
Post a Comment for "Why Does This While Loop Not Work?"