0

I can't find what's wrong but my next code doesn't work:

if finalsum!=0 and (x[0]!='-' or x[0]!='+'):

Do something...

I need to add 2 more conditions If I try only one AND, the code works, if I add the OR, nothing happens.

Also I've tried few more ways to write it and it doesn't work as well.

1
  • @gspr answer is good enough. Unless you want to add more details that clarify your problem in another way Commented Jul 21, 2020 at 12:18

1 Answer 1

4

The x[0]!='-' or x[0]!='+' condition is vacuous. It is always true.

If x[0] is anything other than '-', then first part of the condition is true, so the whole condition is true. If x[0] is anything other than '+', such as for example '-', then the second part of the condition is true, so the whole condition is true. Thus the whole condition is true nomatter the value of x[0].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.