Using JES/Jython:
Function Name: maximum():
Parameters: numbers - list of numbers
Write a function that takes in a list of numbers and determines the largest even and odd numbers. (NOTE: the list of numbers will always contain non-negative numbers).
Test Cases:
>>>maximum([13,15,14,43,12])
The largest even number in the list is 14.
The largest odd number in the list is 43.
>>>maximum([294,3,99,394,500, 97])
The largest even number in the list is 500.
The largest odd number in the list is 99.
def maximum(lst): maxEven = None maxOdd = None for x in lst: if(x%2==0): if(maxEven==None or maxEven<x): maxEven = x else: if (maxOdd == None or maxOdd < x): maxOdd = x print("The largest even number in the list is "+str(maxEven)+".") print("The largest odd number in the list is " + str(maxOdd) + ".") # Testing maximum([13,15,14,43,12]) maximum([294,3,99,394,500, 97])
Get Answers For Free
Most questions answered within 1 hours.