Why is the output of this code "no"? | SoloLearn: Learn to code for FREE!


Why is the output of this code "no"?

if 1+1*3==6: print("yes") else: print("no")

2/6/2016 8:04:00 PM

Muhseen I. Abdullah

4 Answers

New Answer


All of the multiplication occurs first,so you end up with 1*3=3 then it goes on to the next mathematical part, 1+3=4. So when the computer looks at it it sees "if 4 is equal to 6 then true, otherwise false." I hope that helps.


1+1*3 - Python's order of operations is the same as that of normal mathematics: parentheses first, then exponentiation, then multiplication/division, and then addition/subtraction. Here your answer. :)


basic maths teach you this: Everything withing paranthesis first, then division and multiplication, then addition and subtraction. The computer also follows these rules. 1+1*3= 1+(1*3) = 1+3 = 4. 4 != 6.


Python follows the order of operations same as algebra.