I'm just trying to brush on my dragon, so I'm sure I made a basic mistake here. My code is just a toy app that finds the largest item in a circuit-sorted array.
This is my code:
def listIsSorted (l): if l [0] & lt; L [-1]: return 1 return 0 def findLargest (L): listLength = len (L) if (listLength == 1): Return L [0] if (listLength == 2): if (l [0] Return [L] [0] Returns L [1] Halfway = int (listLength / 2) firsthalf = l [ Int (half way)] Second week = l [int (halfway):] If (the first half) and list (second half) were moved to the list: Return Maximum (L [Semi-1], L [-1]) Find the biggest (secondhand) to find Alif (first place on the list): Sabas Larger (Lifes) L4 = [5,1,2,3] Print (Find Largest (L4)) and it outputs to: < My question is why is it being returned as none when it is only Printed as 5?
I think it should be modified in this way because you have to return the result of the recursion call Forgot in:
def findLargest (l): listLength = len (l) if listLength == 1: return L [0] if listLength == 2: If l [0] Gt; L [1]: Print "OMG I found: {0}". Format (L [0]) Return [0] Returns L [1] Halfway = int (listLength / 2) firsthalf = l [: int (First half to return halfway): First to return (half Returns: The second list (first-half) and Listed first (Second half): Return Maximum (L [Semi-1], L [-1] Other: Return Search Largest (First Alf)
No comments:
Post a Comment