+ 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

27th Mar 2022, 3:09 PM
Pythøñ Cúltîst⚔️🔥🇳🇬
Pythøñ  Cúltîst⚔️🔥🇳🇬 - avatar
4 odpowiedzi
+ 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
27th Mar 2022, 3:15 PM
William Owens
William Owens - avatar
+ 3
FF9900 , # Try it print(10*10/10*10)
27th Mar 2022, 3:26 PM
SoloProg
SoloProg - avatar
+ 2
FF9900 , Your answer was correct you deserve full mark.
27th Mar 2022, 6:36 PM
SoloProg
SoloProg - avatar
+ 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...
29th Mar 2022, 6:43 AM
Dikshant Sharma
Dikshant Sharma - avatar