On Mon, Jan 4, 2016 at 1:35 AM, <cc.fezer...@gmail.com> wrote: > Here's my code in python : > > def get_algorithm_result( numlist ): > largest = numlist[0] > i = 1 > while ( i < len(numlist) ): > if ( largest < numlist[i]): > largest = numlist[i] > i = i + 1 > numlist[i] = numlist[-1] > return largest > numlist = [1,2,3,4,5] > largest = get_algorithm_result(numlist) > print largest > def prime_number(x): > return len([n for n in range(1, x + 1) if x % n == 0]) <= 2
I'm a bit uncertain of your indentation here, partly because there's so little of it; what happens in the while loop if the 'if' condition is false? After a 'return' statement, nothing will be executed. If you write code like this: if some_condition: do_stuff() return something do_more_stuff() the second call will never happen - the function will immediately bail out. Maybe you meant for the subsequent code to be unindented? I'm not sure. Have a very careful read of your requirements, and try to lay your code out the exact same way. Put comments against each block of code to show which part of the required algorithm it's performing. That way, you divide the problem up some, and you can look at each piece separately. ChrisA -- https://mail.python.org/mailman/listinfo/python-list