[Tutor] Algorithm
Joel Goldstick
joel.goldstick at gmail.com
Mon Dec 28 12:32:39 EST 2015
On Mon, Dec 28, 2015 at 7:34 AM, cicy felix <cc.fezeribe at gmail.com> wrote:
> 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
>
I believe the code following should not be indented as that makes it part
of your function
> 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
>
> Can you show your unittest code?
> I look forward to your response,
> Thank you!
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
--
Joel Goldstick
http://joelgoldstick.com/stats/birthdays
More information about the Tutor
mailing list