Why output is 10? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

4th Jul 2018, 4:48 PM
Maninder $ingh
Maninder $ingh - avatar
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
4th Jul 2018, 4:54 PM
Agent
Agent - avatar
+ 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?
4th Jul 2018, 5:07 PM
$ยข๐Žโ‚น๐”ญ!๐จ๐“
$ยข๐Žโ‚น๐”ญ!๐จ๐“ - avatar
+ 2
a = 5 b = 7-2 = 5 a+b thats why
4th Jul 2018, 6:40 PM
mwq