Python math | Sololearn: Learn to code for FREE!

+1

Python math

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

8/5/2020 8:11:40 AM

madeline

4 Answers

New Answer

+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.

+6

/ division retruns a float

+5

1st division 6-3+2*2.0 Then multiplication 6-3+4.0 Then 10.0-3 Ans 7.0

+1

🤦‍♀️ thanks