+ 1
Challenge question
print(6+5-4*3/2%1) How is the answer 11.0 6+5 gives 11, -4*3 gives -12 , dividing by 2 gives -6 11-6 = 5 And 5%1 = 0 Why isn't the ans 0
7 Answers
+ 6
Here is a table of order of precedence for operators.
https://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html
So
4 * 3 = 12
12 / 2 = 6
6 % 1 = 0
6 +5 = 11
11 - 0 = 11
+ 3
FF9900 ,
# Try it
print(10*10/10*10)
+ 2
FF9900 ,
Your answer was correct you deserve full mark.
+ 1
Look, As per the order of precedence in Python (PEMDAS).
First we'll do -
2%1 , here percentage sign means remainder. So when we divide 2 by 1 the remainder is 0 so now we have 0.
Next - we have to divide 3 by 0. So obviously it will be 0.0 only. Now according to the order of precedence we have to multiply 4 and 0. And 4 x 0 is 0.0 only.
Now the expression left over is something like -
6+5-0
So 6+5 is 11.0 & 11-0 is 11.0 only. šš»šš»
Remember the order of precedence it will be easy then...