[Tutor] Better way to compare values?
bgailer at gmail.com
Mon Aug 29 03:58:36 CEST 2011
On 8/28/2011 9:19 PM, memilanuk wrote:
> Recently picked back up the Python bug, and have started chipping away
> at the warm-up exercises over @ codingbat.com.
> I'm getting thru the basic stuff okay, but I'm getting a feeling that
> maybe I'm not doing things the 'right' way, even though the results
> are correct.
> Specifically, checking if value 'a' OR value 'b' equal a certain
> The example that I'm on at the moment (like I said, starting over at
> the basics)...
> My solution:
> Given 2 ints, a and b, return True if one if them is 10 or if their
> sum is 10.
> makes10(9, 10) = True
> makes10(9, 9) = False
> makes10(1, 9) = True
> def makes10(a, b):
> if (a == 10) or (b == 10):
> elif a + b == 10:
> In particular, the 'if (a == 10) or (b == 10): line... is there a
> shorter/more compact/more correct (i.e. pythonic) way of testing to
> see if a OR b is equal to 10? stinfo/tutor
if 10 in (a,b) would do it.
Chapel Hill NC
More information about the Tutor