CSCA08H3 Chapter 10: Chapter 10.docx

31 views2 pages

Document Summary

An algorithm is a set of steps that accomplishes a task. We will be looking in to our algorithm- writing technique called top-down design. You start by saying or writing everything in english and then start to pick up what can we write in python, and then you repeat until there is no. For the lowest number in a list: min(x) Find where it is in the list: low = min(x) min_index=x. index(low) """return a tuple of the indices of the two smallest values in list l. """ smallest = min(l) min1 = l. index(smallest) L. insert(min1, smallest) if min1 <= min2: min2 += 1 return (min1, min2) Method sort, identify minimums, get indices def find_two_smallest(l): """return a tuple of the indices of the two smallest values in list l. """ temp_list = l[:] temp_list. sort() smallest = temp_list[0] next_smallest = temp_list[1] min1 = l. index(smallest) min2 = l. index(next_smallest) return (min1, min2) """return a tuple of the indices of the two smallest values in list l. """

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers