Ed Leafe wrote: > On Aug 11, 2007, at 9:28 PM, Jeff Johnson wrote: > >> I want to print "penny" or "pennies" based on the number of >> pennies. How do >> I do that in Python without hard coding the two words? I suppose I >> could >> have a list of singular money and a list of plural money and print >> the one >> that is appropriate; but a good ole FoxPro IIF() would be better. > > If you have Python 2.5 or later you can write it: > > print "penny" if pennies == 1 else "pennies" > > Otherwise, you have to use an if structure: > > if pennies == 1: > print "penny" > else: > print "pennies"
You can actually do: (pennies == 1) and "penny" or "pennies" It's pretty obtuse, but it comes in handy when you just need the one-liner, such as in an expr in the report writer. -- pkm ~ http://paulmcnett.com _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users Searchable Archives: http://leafe.com/archives/search/dabo-users This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]
