Reputation: 9
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.
Upvotes: 0
Views: 318
Reputation: 11227
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]
.
Upvotes: 4