Introduction to Programming using Python 1st Edition

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

Chapter 15 - Recursion - Programming Exercises - Page 524: 15.12

Answer

code

Work Step by Step

# 15.12 (Find the largest number in a list) Write a recursive function that returns the # largest integer in a list. Write a test program that prompts the user to enter a list # of integers and displays the largest element. def getLargest(lst): max = lst[0] return getLargestHelper(lst, 0, len(lst), max) def getLargestHelper(lst, startIndx, endIndx, max): if startIndx == endIndx: return max if lst[startIndx] > max: max = lst[startIndx] return getLargestHelper(lst, startIndx + 1, endIndx, max) lst = input("Enter a list of integers: ").split() lst = [eval(x) for x in lst] print(getLargest(lst))
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.