Ask coding questions

← Back to all posts
if statements not working correctly, please help
Ravost

my code

all it does is prints

form the quit message in the first if statement.
Is it something from the with open(file)... thing?

Answered by ruiwenge2 [earned 5 cycles]
View Answer
Voters
Ravost
Comments
hotnewtop
ruiwenge2

That’s because you used the quit function. remove them

Ravost

thx, it worked i just had to remove the if message.lower() == "quit" or "exit":` ...

CodingElf66

@Ravost I can help! You need to understand the proper use of the or in Python.

If you look at if message.lower() == "quit" or "exit":, it would be re-syntaxed like this:

if (message.lower() == "quit") or "exit":

Which "exit" would return True (un-boolean things return True unless for 1) no matter what, which would result in the whole if statement returning True because you used or. So, to fix it, you do:

if (message.lower() == "quit") or (message.lower() == "exit"):

Which would be the correct solution. Hope this helps, and hope you can mark it as answered!

Ravost

@CodingElf66 also works, i just removed the quit function, but thanks anyway!

CodingElf66
CodingElf66

@Ravost But by the way if you want the system to quit for real, you can do my strategy. Because if you went with @ruiwenge's, all that you do is if the user inputs exit or quit, it just does nothing. So hope this helps and you can mark it as answered!