Jan-22-2019, 08:08 PM
I'm doing a seminar to learn Python, and I've been asked to predict the result of this code:
But here's the result:
print ( 5*2 - 3+4/2 )The lesson explained the order of operations as Parentheses, Exponents, Multiplication and Division, Addition and Subtraction. So I first multiplied 5 by 2 to get 10. Then I divided 4 by 2 to get 2. So now it's 10 - 3 + 2. Then I added 3 to 2 to get 5. Finally, I subtracted 5 from 10. So I predicted the result to be 5.
But here's the result:
Output:9.0
. What's wrong with my calculation? What order of operations could result in 9.0? (I'm using Python 3.)