1+1*false=1~true | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

1+1*false=1~true

how is the solution to this question false? it should be true!

28th Nov 2016, 3:32 AM
G Girish
G Girish - avatar
3 Answers
+ 2
First of all, this is not a working python code. There are at least 3 mistakes in it. 1. The most important. ~ is an unary operator not a binary one. You can use ~x, not a~b. 2. = is an assignment operator. Use == to check for equality. 3. False and True not false and true. Python is case sensitive. Thus, formulate your question correctly to get the right answer.
28th Nov 2016, 11:28 AM
donkeyhot
donkeyhot - avatar
+ 1
The operations aren't performed from left to right. Multiplication happens before addition, so it first figures out 1*false, then adds 1 to that. The result is 1 on the left, and 0 on the right, or 1 == 0, which is false.
28th Nov 2016, 4:46 AM
DaemonThread
DaemonThread - avatar
0
thanks for the reply. :-)
28th Nov 2016, 6:34 AM
G Girish
G Girish - avatar