On Thu, Jan 15, 2009 at 1:08 PM, Alan Gauld <alan.ga...@btinternet.com> wrote: > > "Mr Gerard Kelly" <s4027...@student.uq.edu.au> wrote > >> 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()? > > Move the float inside the eval: > > eval("float(3/2)")
That still does not work, because the 'float' comes after the division. 3/2 equals 1, so float(3/2) equals 1.0. To make it work, you'll have to put the float inside the division: eval("float(3)/2") or eval("3/float(2)") Which, as said before, is written less complicatedly as: eval("3.0/2") -- André Engels, andreeng...@gmail.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor