vendredi 8 janvier 2021

Printing the max and max index within a range in a list

In the code below it randomly selects a range of numbers within the list_. Stop has to be greater than start, and than I want the program to output the maximum number within the list_[start:stop] as well as the order that number is at. I am having an issue printing the index of the functions between a range in the list_.

#15 numbers in the list
list_ = [1,3,5,6,7,2,3,6,4,3,5,7,8,11,10]
stop= random.randint(1, len(list_))
start = random.randint(0, stop)

maxnum = max(list_[start:stop])
max_index = list_.index(maxnum)
print("maximum number in range: ", maxnum, "index of max number: ", max_index)



Aucun commentaire:

Enregistrer un commentaire