0

How to understand this statement

x = 4 y = 2 if not 1+ 1 ==y or x==4 and 7==8: print("Yes") else : print ("No")

16th Dec 2019, 1:43 PM
Vikram Singh
Vikram Singh - avatar
3 odpowiedzi
+ 6
not 1 + 1 == y: ? x == 4: ? 7 == 8: False They are executed like this.
16th Dec 2019, 1:46 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
You need to learn to classify those operators into 3 main classes: Arithmetic, Comparison and Logical. Arithmetic operators are evaluated first. Comparison operators are evaluated before logical operators. Logical operators are evaluated last. In addition those classes can have different operation precedences between different operators. Operation precedence of arithmetic operators work exactly like in maths that were taught on school. Comparison operators might not have. But logical operators, if they are new thing, then it might only need to be either remembered or written up: not first, and second, or last.
16th Dec 2019, 3:58 PM
Seb TheS
Seb TheS - avatar
+ 1
1. Find the result of arithmetic operator 1+1 = 2... 2. Find the result of boolean operators, those are 1+1 == y, x == 4, 7 == 8. See the variable of x and y, 4 and 2. True, true, false... 3. Change the boolean result if there is "not". True become False... 4. Choose "or" bool operation first to clear the answer, after that "and" bool operation. False or True and False -> True and False -> False... 5. As I know, for "if" function, if the answer is True, the output will be "Yes" in that case. And if the answer is False, the output will be "No"... 6. But, I see in your program, below "else :" there is no tab before print ("No"). It will be error if it's like that... 7. Yeah, sometimes we don't care about small things that are not too important until we realize we do a mistake. Even though only one space before ":", I always keep consistent with my typing of programming. So, just be perfect with your own way...
18th Dec 2019, 7:24 AM
Muhammad Syam'un Al-Ghozi
Muhammad Syam'un Al-Ghozi - avatar