Advertisement
cartagenae

Linear Search (finding maximum value)

Nov 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. # Search list
  2. test_scores = [88, 93, 75, 100, 80, 67, 71, 92, 90, 83]
  3.  
  4. #Linear Search Algorithm
  5. def linear_search(search_list):
  6. maximum_score_index = None
  7. for idx in range(len(search_list)):
  8. if not maximum_score_index or search_list[idx] > search_list[maximum_score_index]:
  9. maximum_score_index = idx
  10. return maximum_score_index
  11.  
  12. # Function call
  13. highest_score = linear_search(test_scores)
  14.  
  15. #Prints out the highest score in the list
  16. print(highest_score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement