def our_max(numbers):
result = -9999
for number in numbers:
if result<number:
result = number
return result
print(our_max([1, 2, 10, 9, 3, 7, 0, 99, 27, 85]))
The purpose of the code appears to be to obtain the maximum value among the elements in the list [1, 2, 10, 9, 3, 7, 0, 99, 27, 85].
If you look at the contents of the code, you are repeating the size comparison of each element and the reference value.
You're going to need an arbitrary number to compare numbers. You set the result = -9999 here. To be honest, there is no problem with the example code even if it is -1.
You can use the max command without having to use these functions, but... It's written for something.
To be honest, it's right to ask the person who wrote the code directly rather than the others.
© 2024 OneMinuteCode. All rights reserved.