[Tutor] eval func with floating...

Troels Emtekær Linnet tlinnet at gmail.com
Tue Aug 23 12:27:27 CEST 2011


Thats because you do integer division.

Do either:

float(15)/8
15/float(8)
15.0/8
15/8.0

Just be sure, that either 15 or 8 is a float, and not both an integer.

Best
Troels


2011/8/16 simulacrx <simulacrx at gmail.com>

>  hi;
> -----------------------
> check=(1,2,3,4,5,6,7,8,9,"/","*","-","+","(",")","[","]")
>
> while True:
>     a=raw_input("type your query : \n")
>     c=set(a).intersection(set(check))
>
>     if c:
>         print *eval("float(%s)"%a)*
>     else:
>         print "error! please use -defined operators-!"
> -----------------------------
>
> this script works.. but if i type
>
> 15/8
>
> it returns 1.. no floatin'.. i must fix this? can anyone help me?
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110823/a996509a/attachment.html>


More information about the Tutor mailing list