+ 1

Why is the output of this code "no"?

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

6th Feb 2016, 8:04 PM
Muhseen I. Abdullah
Muhseen I. Abdullah - avatar
4 Answers
+ 6
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.
16th Feb 2016, 11:52 PM
Jake Goodwin
Jake Goodwin - avatar
+ 3
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. :)
5th Mar 2016, 11:22 AM
Tang
Tang - avatar
+ 1
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.
14th Jun 2016, 1:35 AM
Vegard Bratteng
Vegard Bratteng - avatar
+ 1
Python follows the order of operations same as algebra.
28th Jul 2016, 10:32 PM
daniel fancher
daniel fancher - avatar