[Tutor] Algorithm

cicy felix cc.fezeribe at gmail.com
Mon Dec 28 07:34:36 EST 2015


Hello there!
Thank you for the good work you are doing at helping newbies to python.
Please I'd like clarification with the exercise below:

  Create a function get_algorithm_result to implement the algorithm below
Get a list of numbers L1, L2, L3....LN as argument
Assume L1 is the largest,  Largest = L1
Take next number Li from the list and do the following
If Largest is less than Li
   Largest = Li
 If Li is last number from  the list then
  return Largest and come out
 Else repeat same process starting from step 3

This what I've come up with:

def get_algorithm_result( numlist ):
 largest = numlist[0]
 i = 1
 while ( i < len(numlist) ):
   if ( largest < numlist[i]):
     largest = numlist[i]
     i = i + 1
     return largest
     numlist1 = [1,2,3,4,5]
     numlist2 = [10,20,30,40,50]
     largest = get_algorithm_result(numlist1)
     print largest
     largest = get_algorithm_result(numlist2)
     print largest

And I keep getting this error :
  .  test_maximum_number_two
Failure in line 15, in test_maximum_number_two    self.assertEqual(result,
"zoo", msg="Incorrect number") AssertionError: Incorrect number
Using unittest

I look forward to your response,
Thank you!


More information about the Tutor mailing list