[Tutor] eval func with floating...
Peter Otten
__peter__ at web.de
Tue Aug 23 12:52:10 CEST 2011
simulacrx wrote:
> check=(1,2,3,4,5,6,7,8,9,"/","*","-","+","(",")","[","]")
You have to quote the digits: 1 is an integer while "1" is a string of
length one:
>>> "1" == 1
False
Also, you forgot the "0".
Note that there's no need to use a tuple as set() will happily accept a
string:
check = set("0123456789/*-+,()")
> 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?
More information about the Tutor
mailing list