+ 1

I’m extremely confused, please do answer in detail..

x=4 y=2 if not 1+1==y or x==4 and 7==8 print(“Yes”) elif x>y print(“No”) • Yes • No • Yes No

26th Jul 2020, 4:24 PM
17077071
17077071 - avatar
6 odpowiedzi
+ 6
In: not 1+1==2 or 4==4 and 7==8 + operations have the highest operation precedence, thus + operations are evaluated first: 1+1 ---> 2 We get: not 2==2 or 4==4 and 7==8 Where the comparison operators have the highest operation precedence, let's evaluate the comparison operations: 2==2 ---> True 4==4 ---> True 7==8 ---> False We get: not True or True and False Where not has the highest precedence: not True ---> False We get: False or True and False Where and has the highest operation precedence: True and False ---> False We get: False or False ---> False
26th Jul 2020, 5:13 PM
Seb TheS
Seb TheS - avatar
+ 3
You can use braces to clarify your doubts, they would make the single conditions a bit better readable and understandable. Then you'll see, that the conditions for // edit see other post.
26th Jul 2020, 4:33 PM
Sandra Meyer
Sandra Meyer - avatar
+ 3
Sorry, didn't read it accurate - first branch is not evaluated as true due to that "and 7==8".
26th Jul 2020, 4:36 PM
Sandra Meyer
Sandra Meyer - avatar
+ 3
ya.. and when I went for the 3rd option, it said that it was wrong..
26th Jul 2020, 4:37 PM
17077071
17077071 - avatar
+ 3
It is, see my second post, sorry 😉
26th Jul 2020, 4:38 PM
Sandra Meyer
Sandra Meyer - avatar
+ 3
it’s ok
26th Jul 2020, 4:39 PM
17077071
17077071 - avatar