Re: Simple integer comparison problem

2007-04-14 Thread Anton Vredegoor
Bart Willems wrote: > I have a feeling that there's a Python-solution that is shorter yet > better readable, I just can't figure it out yet... Shorter (and faster for big lists): Yes. More readable: I don't know, I guess that depends on ones familiarity with the procedure. import bisect def g

Re: Simple integer comparison problem

2007-04-14 Thread Bart Willems
> if points > 89 and points <= 100: > return "A" > elif points > 89 and points <= 89: > return "B" > elif points > 69 and points <= 79: > return "C" > elif points > 59 and points <= 69: > return "D" > else: > return "F" The previous poste

Re: Simple integer comparison problem

2007-04-14 Thread tom
Thanks for help! -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple integer comparison problem

2007-04-14 Thread Dan Bishop
On Apr 14, 10:19 am, [EMAIL PROTECTED] wrote: > Hi! > I ran in problem with simple exercise. I'm trying to get program to > return grade when given points but no matter what, I always get F. > > def grader(): > print "Insert points: " > points = raw_input('> ') > int(points) > >

Re: Simple integer comparison problem

2007-04-14 Thread Jakub Stolarski
On Apr 14, 5:19 pm, [EMAIL PROTECTED] wrote: > Hi! > I ran in problem with simple exercise. I'm trying to get program to > return grade when given points but no matter what, I always get F. > > def grader(): > print "Insert points: " > points = raw_input('> ') > int(points) > >

Simple integer comparison problem

2007-04-14 Thread tom
Hi! I ran in problem with simple exercise. I'm trying to get program to return grade when given points but no matter what, I always get F. def grader(): print "Insert points: " points = raw_input('> ') int(points) if points > 89 and points <= 100: return "A" eli

Re: Comparison problem

2005-11-28 Thread Peter Hansen
Tim Henderson wrote: > peter (Thanks for clarifying to whom you were responding... I saw the other post but wouldn't have responded since it didn't seem to be in response to one of mine. :-) ) > would not the more correct way to do this be short circuit > evaluation. somthing along lines of >

Re: Comparison problem

2005-11-27 Thread Tim Henderson
peter would not the more correct way to do this be short circuit evaluation. somthing along lines of if (len(item) > 0) and (item[0] == '-'): pass seems to be the more correct approach. rather than relying on slicing to return an empty string. For instance suppose you wanted to test to see if th

Re: Comparison problem

2005-11-27 Thread Tim Henderson
of course the more correct way is most likely the use of short circuit evaluation. so somthing along lines of if (len(item) > 0) and (item[0] == '-'): pass would probably be the correct approach. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparison problem

2005-11-27 Thread Peter Hansen
Fredrik Lundh wrote: > Peter Hansen wrote: >>Actually, it's not so much baroque as it is safe... item[0] will fail if >>the string is empty, while item[0:1] will return '' in that case. >> >>Of course, as you point out, .startswith() is the better approach anyway. > > $ timeit -s "s = 'abc'" "s[:1

Re: Comparison problem

2005-11-27 Thread [EMAIL PROTECTED]
I think no matter what language you programs it, it is hard to understand. Can you break it up into sub-problems first ? Like first parsing the inventory file into a python dict, then also the fields from web to another dict ? Chris wrote: > Hi, > > I'm new to python, and I'm trying to write a sma

Re: Comparison problem

2005-11-27 Thread Fredrik Lundh
Peter Hansen wrote: > Actually, it's not so much baroque as it is safe... item[0] will fail if > the string is empty, while item[0:1] will return '' in that case. > > Of course, as you point out, .startswith() is the better approach anyway. $ timeit -s "s = 'abc'" "s[:1] == 'a'" 100 loops, be

Re: Comparison problem

2005-11-26 Thread Alex Martelli
Tom Anderson <[EMAIL PROTECTED]> wrote: ... > But, more importantly, egad! What's the thinking behind having slicing > behave like that? Anyone got any ideas? What's the use case, as seems to > be the fashionable way of putting it these days? :) Slicing has always been "soft" (it's OK to specif

Re: Comparison problem

2005-11-26 Thread Peter Hansen
Tom Anderson wrote: > On Sat, 26 Nov 2005, Peter Hansen wrote: >>Tom Anderson wrote: >>>On Sat, 26 Nov 2005, Chris wrote: if item[0:1]=="-": >>> >>>item[0:1] seems a rather baroque way of writing item[0]! I'd actually >>>suggest writing this line like this: >> >>Actually, it's not so much ba

Re: Comparison problem

2005-11-26 Thread Tom Anderson
On Sat, 26 Nov 2005, Peter Hansen wrote: > Tom Anderson wrote: >> On Sat, 26 Nov 2005, Chris wrote: >> >>> if item[0:1]=="-": >> >> item[0:1] seems a rather baroque way of writing item[0]! I'd actually >> suggest writing this line like this: > > Actually, it's not so much baroque as it is saf

Re: Comparison problem

2005-11-26 Thread Peter Hansen
Tom Anderson wrote: > On Sat, 26 Nov 2005, Chris wrote: > >> if item[0:1]=="-": > > item[0:1] seems a rather baroque way of writing item[0]! I'd actually > suggest writing this line like this: Actually, it's not so much baroque as it is safe... item[0] will fail if the string is empty, while

Re: Comparison problem

2005-11-26 Thread Tom Anderson
Chris, as well as addressing what i think is causing your problem, i'm going to point out some bits of your code that i think could be polished a little. It's intended in a spirit of constructive criticism, so i hope you don't mind! On Sat, 26 Nov 2005, Chris wrote: >if item[0:1]=="-": it

Comparison problem

2005-11-26 Thread Chris
Hi, I'm new to python, and I'm trying to write a small python script for a webpage. The script opens up a file called inventory, reads the contents, and checks the contents against the data from the form in my webpage. Now I have to do some slicing to get the name of the form elements (in this c