Mr Gerard Kelly wrote:
Thanks very much

I've noticed that the eval() function gives an integer, so eval("3/2")
gives back 1. float(eval("3/2")) doesn't seem to work, any way to get a
floating point number back with eval()?

I know you can just do ("3./2."), but is there any way to do it with
just ("3/2")?

If you are using a current version of Python, the line:

from __future__ import division

will make division with the "/" return a float; you then use "//" for integer division....

>>> from __future__ import division
>>> eval("3/2")
1.5
>>> eval("3//2")
1
>>>

Cheers,
Vern

--
This time for sure!
   -Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
vce...@canterburyschool.org; 260-436-0746; FAX: 260-436-5137
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to