x, y and z, each representing a side of a triangle. The function should return -1 if any of the sides is less than or equal to zero:
if x <= 0: return -1 elif y <= 0: return -1 elif z <= 0: return -1
Fred notices that this can be simplified into a single if—we don't need the complication of the if/elif/elif here. What should we fill in for the condition of this single if? Fill in the blank below:
if (_______________________________________): return -1Hint: think carefully: do you need
and or do you need or?
if x > 0 and y > 0 and z > 0:
return -1
if ( x or y or z <= 0 ):
return -1
if (x <=0 or y<= 0 or z <= 0 ):
return -1
if not ( x > 0 and y > 0 and z > 0 ):
return -1
We've gone over recursion in this course as it applies to lists in Python. We've looked at how to use recursion to do the following things in Python:
'No number on the list is >100'largestAbs() that returns the item on the a list of numbers with the largest absolute value. (In Python, abs() finds the absolute value of a number). For example, largestAbs([3,-9,2,5]) returns -9, and largestAbs([3,-9,10,2,5]) returns 10. Hint: be sure that you return the number itself, and not the absolute value of the largest number.lengths(["This", "is" , "a", "test"]) returns [4, 2, 1, 4]