Question: 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
Get step-by-step solutions from verified subject matter experts
