Dec-26-2018, 01:28 PM
Based on @Ichabod’s and @buranfor’s feedback, here are the changes I have made since my last forum post:
With these changes, here is what my script looks like now:
But I am actually getting:
It partially worked. I’ve tried many combinations at lines 4, 6, 9, and 11 (swapping
What would I need to change in my script to produce the expected output?
The answer key from the instructor is much simpler and less complicated. It reads:
- I replaced the line which previously read
elif (a % 2 and b % 2) != 0:
to justelse
- I removed the explicit
pass
operation
- I replaced the print statements with return
- I removed the explicit boolean references. Instead of
if (a % 2 and b % 2) != 0:
I now just use:if a % 2 and b % 2:
With these changes, here is what my script looks like now:
def lesser_of_two_evens(a,b): if a % 2 and b % 2: if b < a: return a if a > b: return b else: if a < b: return b else: return aAs outlined initially, I’m expecting the following output:
Quote:lesser_of_two_evens(2,4) --> 2
lesser_of_two_evens(2,5) --> 5
lesser_of_two_evens(245,13) --> 245
lesser_of_two_evens(52,10) --> 10
But I am actually getting:
Quote:lesser_of_two_evens(2,4) --> 4
lesser_of_two_evens(2,5) --> 5
lesser_of_two_evens(245,13) --> 245
lesser_of_two_evens(52,10) --> 52
It partially worked. I’ve tried many combinations at lines 4, 6, 9, and 11 (swapping
a
and b
) and then running the script and testing the output. The output is correct for two lines, but then the other two test output lines are incorrect.What would I need to change in my script to produce the expected output?
The answer key from the instructor is much simpler and less complicated. It reads:
def lesser_of_two_evens(a,b): if a%2 == 0 and b%2 == 0: return min(a,b) else: return max(a,b)Even with this as the most elegant solution, how would you folks modify my script to return the correct output?