>
> 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
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.
>
> 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
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
> 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
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
>
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
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".
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
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
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-!"
-
11 matches
Mail list logo