Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

The problem is this Design a function that accepts a list as an argument and returns the largest value in the list. The function should

The problem is this

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.

My coding so far is this

def main(): # Prints the largest value in list user_input = input('Enter a list of numbers seperated by a space: ') user_list = user_input.split() print('Largest number is ', max_Number(user_list), '.') # Recursion function that finds the maximum number in a sequence of n elements def max_Number(S, n): if n == 1: # Reaches the leftmost element in list return S[n-1] else: # Searches and compares numbers until largest is found previous = max_Number(S, n-1) current = S[n-1] if previous > current: return previous else: return current main()

However, I keep getting this type error

print('Largest number is ', max_Number(user_input), '.') TypeError: max_Number() missing 1 required positional argument: 'n'

What can I do to fix this problem and keep it recursive? Also, I would like for the string to accept as many numbers as the user would like.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions