Python complaints

James Logajan JamesL at Lugoj.Com
Thu Nov 25 14:48:09 EST 1999


Oleg Broytmann wrote:
> 
> On Wed, 24 Nov 1999, James Logajan wrote:
> > def ifexp(cond, trueVal, falseVal):
> >    if cond:
> >       return trueVal
> >    else:
> >       return falseVal
> >
> > print "You scored %s point%s" % (score, ifexp(score == 1, "", "s"))
> 
>    The problem with this solution is that python will calculate both
> expressions (trueVal, falseVal) even if "cond" is false - what is VERY
> undesireable in most situations. What if I just cannot calculate falseVal
> if "cond" is false?
> 

Then how about:

if score == 1: suffix = ""
else: suffix = "s"
print "You scored %s point%s" % (score, suffix)

I better put a <wink> in here; never know when the terminally lazy might
become terminally ballistic! Besides the pluralization algorithm isn't
portable to other languages (such as German...(do I need to add another
wink?))




More information about the Python-list mailing list