+ 1

Python math

print(6-3+2*4/2) Why does this print 7.0 and not -1? Thanks!

5th Aug 2020, 8:11 AM
madeline
madeline - avatar
4 Answers
+ 8
It works according to its precedence. First, multiplication and division Then, addition and subtraction. So: 4/2=2.0*2=4.0 #or 2*4/2=8/2=4.0 #Then: 6-3=3+4.0=7.0 #or 7.0+3=10.0-3=7.0 Python doesn't works according to your order. It follows it's precedence of operators.
5th Aug 2020, 8:16 AM
Arctic Fox
Arctic Fox - avatar
+ 6
/ division retruns a float
5th Aug 2020, 8:13 AM
Slick
Slick - avatar
+ 5
1st division 6-3+2*2.0 Then multiplication 6-3+4.0 Then 10.0-3 Ans 7.0
5th Aug 2020, 8:13 AM
TOLUENE
TOLUENE - avatar
+ 1
đŸ€Šâ€â™€ïž thanks
5th Aug 2020, 8:16 AM
madeline
madeline - avatar