+ 7

Why it giving output 0.0?

print(6/3%2*3//2) #output=0.0 but according operator precedence output should be 1.0 but why ,can anyone explain this.

7th Jun 2018, 11:42 AM
Maninder $ingh
Maninder $ingh - avatar
6 Answers
+ 3
Thanks Donna now I know how this works. />//>%>*>+>- 6/3=2.0 3//2=1 2.0%2=0 0*1=0
7th Jun 2018, 11:59 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Maninder Singh division has a higher precedence than multiplication, in pretty much any case
7th Jun 2018, 1:00 PM
hinanawi
hinanawi - avatar
+ 1
BlazingMagpie confirming your comment that equal precedence operations are applied left to right >>> 2*3%2 0 >>> 3%2*2 2 >>> 2*3//2 3
8th Jun 2018, 2:30 AM
1_coder
0
hinanawi That's not how operation precedence works. Multiplication and division have same precedence, so you do then in order from left to right.
7th Jun 2018, 8:53 PM
BlazingMagpie
BlazingMagpie - avatar
0
BlazingMagpie talking programming here, sorry for not specifying
7th Jun 2018, 8:58 PM
hinanawi
hinanawi - avatar
0
>>>6/3%2*3//2 >>>2%2*1 >>>2%2 >>>0
8th Jun 2018, 9:17 AM
SAURABH YADAV
SAURABH YADAV - avatar