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.
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()
for i in range(len(user_list)):
user_list[i] = int(user_list[i])
print('Largest number is ', max_Number(user_list, len(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()

The problem is this Design a function that accepts a list as an argument and returns...
Question 1 100 pts Design a function that accepts a list of numbers as an argument (this function only has one parameter, which is a list). The function should recursively calculate the sum of all the numbers in the list and return that value. Hint: refer to the Summing a range of list elements with recursion" example in slides.
For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...
def createList(): user_input = input("Enter a numbers seperated by a comma:") user_list = user_input.split(',') return user_list def remove_duplicates(user_list): test = [] for i in user_list: if i not in test: test.append(i) x= print("Original List :",user_list) y= print("List after removing duplicates:", test) return x,y def main(): createList() remove_duplicates(user_list) main() why isnt user_data being passed through to remove_duplicates(user_list)? Explanation too please
urgent Help needed in python program ! Thanx # This is a function definition. You can ignore this for now. def parse_integer_list_from_string(string): """ Returns a list of integers from a string containing integers separated by spaces. """ # Split the line into a list of strings, each containing a number. number_string_list = string.split() # Create an empty list to store the numbers as integers. numbers = [] # Convert each string to an integer and add it to the list...
Python Program Only: Write the function definition only of the "get(self, index)" function. Plug your method in the code file shared with you and test it in the main to get the element at index 3 of mylist2 . class Node: def __init__(self, e): self.element = e self.next = None class LinkedList: def __init__(self): self.head = None self.tail = None self.size = 0 def addFirst(self, e): newNode = Node(e) newNode.next = self.head self.head = newNode self.size = self.size + 1...
Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...
#function to covert kilometer to miles #takes km input as an argument and return the calculation def kilometer_to_miles(km): return km * 0.6214 #function to covert miles to kilometer #takes miles input as an argument and return the calculation def miles_to_kilometer(miles): return miles/0.6214 #Main function to find the distance #by calling either of the two functions #prompt the user to enter his/her choice of distance conversion restart = 0 while (restart == 'y'): user_input = input ("Enter k to convert kilometer...
i have no lean break. so below is my way. can you fix it.
Test Input Result print (read_number_list()) 999 [] print (read_number_list)) 1 Answer (penalty regime: 0, 10, 20, 30, 40, 50%) 1 def read_number_list(): alist = [] while True: - numberinput("") if number -999: 4 return a listl else: a_list.append (int (number)) 9 1e 12 Precheck Check Test Input Expected Got print (read_number_list()) 999 [] Runtime error** Traceback (most recent call last): File "prog.python3", line 29, in <module>...
Sum of Numbers Problem: Write a method that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the method will return the sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum. Demonstrate the method in a program. The program should be called SumOfNumbers.java.
Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...