Question:
how to find max and min in a list with python using for loops?
2011-07-21 15:01:16 UTC
i know how to use the max/min function in python, but for my class i have to use a for loop. here are the instructions: "given the python list [5,8,9,10] write a python program which uses a for loop to identify the largest integer in the list.

Thanks
Four answers:
2011-07-21 15:15:40 UTC
you can either sort the list first, or you can write a function to compare integers and call that effectively from your for loop, storing and returning the results.



(pseudocode)



bool greaterThan(int1, int2)

return int1>int2



for (i -> listsize)

min = list[0]

max = list[0]



if greaterThan(min, currentNumber)

min = currentNumber

if greaterThan(currentNumber, max)

max = currentNumber



return min, max



OR



int[] sort(int[] myArray)

\\do sorting magic here (fun stuff!)



max = myArray[length-1]

min = myArray[0]



return min, max
?
2016-12-08 19:50:23 UTC
Min Python
?
2016-09-29 10:15:25 UTC
Python Min
Chen
2015-09-13 05:45:20 UTC
This Site Might Help You.



RE:

how to find max and min in a list with python using for loops?

i know how to use the max/min function in python, but for my class i have to use a for loop. here are the instructions: "given the python list [5,8,9,10] write a python program which uses a for loop to identify the largest integer in the list.



Thanks


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...