Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function called largest that takes a list of integers as argument. It re

ID: 3823717 • Letter: W

Question

Write a function called largest that takes a list of integers as argument. It recursively returns the largest integer of the list. Here are few sample runs: >>> largest([1, 12, 4, 10]) 12 >>> Largest ([]) Traceback (most recent call last): File print (Largest ([])) File raise ValueError ('Please provide a non empty list') Value Error: Please provide a non empty list >>> Larges ([1, 2.2]) Traceback (most recent call last): File xxxxx print Largest ([1, 2.2])) File xxxxx raise Type Error ('the passed argument is not an array') Type Error: the passed argument is not an array Please name your file: largest py and submit it on Mimir.

Explanation / Answer

Ans:: Explained the python code with comments (#).Thank you.

# ;largest

def Largest(list):

if len(list) == 1: # if len == 1

return list[0] # return

else: # else

m = Largest(list[1:]) # largest()

return m if m > list[0] else list[0] # condition m> list[0]

#main

def main():

list = eval(raw_input("Enter a list of the numbers: ")) # input numbers

print("The largest number of list is: ", Largest(list)) # outputs largest of list

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote