Stay N Tom

Showing a slice of what it means to be Thomas.

Pages

Tuesday, September 20, 2011

Math Operators Are Standing By.......

Let's talk about math in python. There is addition (+), subtraction is a hyphen (-), multiplication (*), now were on to division. Type:

>>> print 6/2

You should see this:

>>> print 6/2
3

now if you type 3/2 it will show:

>>> print 3/2
1

Everyone knows three divided by two is one remainder one! Why is python doing this? Well it's actually trying to be smart. 

To fix this type:

>>> 3.0/2

It should look now like this:

>>>3.0/2
1.5

You can also  do (12 + 2)*1

2 + 7 * 4

(This will give you 30 because of the python language which does 7 * 4 + 2)

No comments:

Post a Comment