Counting | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Counting

Hello!! please tell me how this output(answer) is 15??? x=5 if(not(x*2==10)): print(x*2) else: print(x*3) tell me below

3rd May 2018, 6:14 PM
Ayaan
2 Answers
+ 4
(5*2 == 10) returns true, but the not inverts it to false. So it moves to the else statement and prints 5*3 which is 15
3rd May 2018, 6:17 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 1
Basically what Aaron Eberhardt said: The if statement is if(not(x * 2 == 10)): So first it checks the statement x * 2 == 10 which is True (as x = 5). Then it checks the "not" or the inverse of that statement, which is false. So you are essentially checking if(False): print(x*2). Quite obviously, this will not happen, so instead it moves on the the else statement, which involves printing x * 3, which is 15.
3rd May 2018, 10:28 PM
blackcat1111
blackcat1111 - avatar