Question: 4.Largest List Item Design a function that accepts a list as an argument and returns the largest value in the list. The function should use

4.Largest List Item

Design a function that accepts a list as an argument and returns the largest value in the list. The function should use recursion to find the largest item.

This is the code I got so far. I am just stuck on the else statement. I need some help with that or at least explaining it. It needs to be a recursive function

if you could add comments to the else statement so i understand what is going to be written there I would appreciate it. thank you

#Design a function that accepts a list as an argument and returns the largest #value in the list. The function should use recursion to find the largest item.

def main1():

#ask the user for a list

list = [1, 5, 6, 7, 3, 9, 2, 15, 20, 2]

print(get_lrg_value(list))

def get_lrg_value(list):

if len(list) == 1:

return list[0]

else:

return list[0] if list[0] > get_lrg_value(list[1:]) else get_lrg_value(list[1:])

main1()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!