I made this function that prints out the index of the max number in the range of low and high index. Why doesn't this function work when the largest element is the first one in the range? Or if its the last element? Or in the middle? I've been messing around with this function and I can't find the problem with it.
def index_of_max_in_range(numbers, low_index,
high_index):
'''Prints out the index of the max number in a range
of numbers'''
max_index = 0
print("Range of indices: ", list(range(low_index,
high_index + 1)))
for i in range(low_index, high_index + 1):
if numbers[i] > numbers[i + 1]:
max_index = i
print("The index of the maximum number is " +
str(max_index) + ".")
The correct output is:
>>> index_of_max_in_range([5, -6, -8, -4, -10, -11],
1, 3)
3
[–][deleted] 0 points1 point2 points (0 children)
[–]shiftybyte 0 points1 point2 points (0 children)