+ 4
Why output is 10?
a=5 b=7 if not a!=b-2: b=--a print(a+b) #output=10 can you explain me why?
3 Answers
+ 9
a=5
b=7
if not a! =
This means if a is equal
This is because there are two negatives:
not is a negative
! is the same as not so this is a negative
two negatives give a positive/oppostie
So if a is equal to
b-2 same as 5-2
which means 5
summarise it is saying
if a=5
if a is equal to 5
b=âa sama as b=5
print(a+b)
a is still 5
b is now 5
5+5 = 10
+ 3
You should first try by printing values. Printing is the best Technic you should try when you not understand the code.
you are assgining b to value 5.
try to run below code, you will get idea.
a=5
b=7
print(-a)
print(--a)
if not a!=b-2:
b= --a
print(a,b)
print(a+b) #output=10 can you explain me why?
+ 2
a = 5
b = 7-2 = 5
a+b
thats why