division
Egor Bolonev
ebolonev at front.ru
Sun Jun 22 21:35:30 EDT 2003
> > Hi, i am writing a maths program where i get input from the user and
store
> > it in
> > a string. i then use the eval fucntion to return the right answer. users
> > could type in
> > "(23+ 21) - (4 * 3) + 2" for example and the function would return an
int
> of
> > 34 which
> > I would convert to a string. The problem is division, I would like it
that
> > only
> > exact division was aloud, I mean no remainders. In python "22 / 5"
returs
> > an int of 5
>
> I meant to type 4
>
> > i would like if that was illegal because 5 doesnt go into 22 , 4 times
> > exactly, and have the eval
> > function raise an execption which i could handle.
>>> 22/5
4
>>> 22.0/5
4.4000000000000004
>>> a=0.0
>>> (22+a)/5
4.4000000000000004
>>>
--
Egor
More information about the Python-list
mailing list