division bug?

Steven Rumbalski srumbalski at copper.net
Wed Jun 9 12:51:38 EDT 2004


Milan wrote:

> a program:
> 
> a=10
> b=5
> print a/b
> 
> and its result: 0. If you run the program, you see always a sero (0),
> but 10/5 is 2. Who can help me?

You probably have reversed a & b in your program somewhere.  Zero is the
correct result with the numbers reversed.

>>> a = 10
>>> b = 5
>>> print "a/b = %s\nb/a = %s" % (a/b, b/a)
a/b = 2
b/a = 0

If you import division from __future__ my guess is that you will see the
result of 0.5.  If this is the case you have mixed a & b up somewhere.

>>> from __future__ import division
>>> print "a/b = %s\nb/a = %s" % (a/b, b/a)
a/b = 2.0
b/a = 0.5


-- 
Steven Rumbalski
news|at|rumbalski|dot|com



More information about the Python-list mailing list