Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 10 - Lists - Programming Exercises - Page 350: 10.8

Answer

code

Work Step by Step

# 10.8 (Find the index of the smallest element) Write a function that returns the index of # the smallest element in a list of integers. If the number of such elements is greater # than 1, return the smallest index. Use the following header: # def indexOfSmallestElement(lst): # Write a test program that prompts the user to enter a list of numbers, invokes this # function to return the index of the smallest element, and displays the index. def indexOfSmallestElement(lst): smallest = float("inf") smallestInd = 0 for x in range(len(lst)): if lst[x] < smallest: smallest = lst[x] smallestInd = x return smallestInd def main(): lst = [0, 3, 4, 5, 7, 8] print(indexOfSmallestElement(lst)) main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.