Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 1 Lnai 9851

Authors: Paolo Frasconi ,Niels Landwehr ,Giuseppe Manco ,Jilles Vreeken

1st Edition

3319461273, 978-3319461274

More Books

Students also viewed these Databases questions

Question

Analyse the various techniques of training and learning.

Answered: 1 week ago