Re: [Tutor] eval func with floating...

2011-08-24 Thread Christopher King
> > If the user ever sees an AssertionError, your code is buggy. > Well you saw that I caught the AssertionError, so the user wouldn't technically see it. For the other stuff, I didn't know the etiquette for assertion statements. ___ Tutor maillist - Tu

Re: [Tutor] eval func with floating...

2011-08-23 Thread Steven D'Aprano
Christopher King wrote: If the user ever sees an AssertionError, your code is buggy. Well you saw that I caught the AssertionError, so the user wouldn't technically see it. For the other stuff, I didn't know the etiquette for assertion It's not etiquette, it is the actual way assert works.

Re: [Tutor] eval func with floating...

2011-08-23 Thread Christopher King
> > If the user ever sees an AssertionError, your code is buggy. > Well you saw that I caught the AssertionError, so the user wouldn't technically see it. For the other stuff, I didn't know the etiquette for assertion ___ Tutor maillist - Tutor@python.o

Re: [Tutor] eval func with floating...

2011-08-23 Thread Steven D'Aprano
Christopher King wrote: if c: print *eval("float(%s)"%a)* else: print "error! please use -defined operators-!" I would use a assert statement for more readability, like so. *try: assert c* *except AssertionError: print "error! please use -defined operators-!"* else: *pri

Re: [Tutor] eval func with floating...

2011-08-23 Thread Christopher King
> if c: > print *eval("float(%s)"%a)* > else: > print "error! please use -defined operators-!" > I would use a assert statement for more readability, like so. *try: assert c* *except AssertionError: print "error! please use -defined operators-!"* else: *print *eval("float(%s

Re: [Tutor] eval func with floating...

2011-08-23 Thread Peter Otten
Chanakya Mitra wrote: [simulacrx] > c=set(a).intersection(set(check)) [Chanakya Mitra] > shouldn’t this be: > c=set(a).issubset(set(check)) > ? > set(a).intersection(set(check)) will be true as long as only one element > appears in both. ie. 15/a8 kill the process and spit out an error instead >

Re: [Tutor] eval func with floating...

2011-08-23 Thread Chanakya Mitra
ators-!" Sent: 23 August 2011 12:53 To: tutor@python.org Subject: Re: [Tutor] eval func with floating... On Tue, Aug 23, 2011 at 6:52 AM, Peter Otten <__pete...@web.de> wrote: simulacrx wrote: > check=(1,2,3,4,5,6,7,8,9,"/","*","-","+&qu

Re: [Tutor] eval func with floating...

2011-08-23 Thread Joel Goldstick
On Tue, Aug 23, 2011 at 6:52 AM, Peter Otten <__pete...@web.de> wrote: > 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".

Re: [Tutor] eval func with floating...

2011-08-23 Thread Peter Otten
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

Re: [Tutor] eval func with floating...

2011-08-23 Thread Troels Emtekær Linnet
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 > hi; > --- > check=(1,2,3,4,5,6,7,8,9,"/","*","-","+","(",")","[","]") > > whi

[Tutor] eval func with floating...

2011-08-23 Thread simulacrx
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-!" -