Standard Algorithms: Find Minimum/Maximum.
| Created | |
|---|---|
| Tags |
There are two standard algorithms here, with a similar layout.
Find Maximum:
set array to [1,2,3,5,4,6,5,7,6] #creates an array of numbers
maximum = array[0]
from 1 to length of array - 1: #we are starting the comparisons from the first number
if array[counter] > maximum:#remember counter increases every time the loop is run
maximum = array[counter] #we change the maximum to the new largest number.
display the highest score.Find Minimum (real python)
Note that this standard algorithm only changes the comparison sign from > to <.
marks = [12,15,50,22,11,88,50,90,42,33]
minimum = marks[0]
for item in range(1,10):
if marks[item] < maximum:
minimum = marks[item]
print(maximum,"is the lowest number in the list of marks\n")