Answer the question
In order to leave comments, you need to log in
The search functions for the maximum and minimum element output the same index. Why?
def f_max(mas):
i = 0
max_ar = mas[0]
for i in range(len(mas)):
if mas[i] > max_ar:
max_ar = mas[i]
return max_ar
def f_maxIndex(mas):
i = 0
max_ar = mas[0]
for i in range(len(mas)):
if mas[i] < max_ar:
max_ar = mas[i]
return i
def f_min(mas):
i = 0
min_ar = mas[0]
for i in range(len(mas)):
if mas[i] < min_ar:
min_ar = mas[i]
return min_ar
def f_minIndex(mas):
i = 0
min_ar = mas[0]
for i in range(len(mas)):
if mas[i] < min_ar:
min_ar = mas[i]
return i
count = input().split()
array = [int(x) for x in count]
print('Максимальный элемент массива=', f_max(array), ',а его индекс=', f_maxIndex(array))
print('Минимальный элемент массива=', f_min(array), ',а его индекс=', f_minIndex(array))
Answer the question
In order to leave comments, you need to log in
Because you don't change these functions in any way i
. She ran the whole cycle and came back.
for i in range(len(mas)):
if mas[i] < max_ar:
max_ar = mas[i]
return i
def f_maxIndex(mas):
max_index = 0
max_ar = mas[0]
for i in range(len(mas)):
if mas[i] > max_ar:
max_ar = mas[i]
max_index = i
return max_index
def f_minIndex(mas):
min_index = 0
min_ar = mas[0]
for i in range(len(mas)):
if mas[i] < min_ar:
min_ar = mas[i]
min_index = i
return min_index
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question