Question

Using JES/Jython: Function Name: maximum(): Parameters: numbers - list of numbers Write a function that takes...

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.

Homework Answers

Answer #1
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])

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using JES/Jython Function Name: sortMusic() Parameters: Name -string of artist’s name Write a function that finds...
Using JES/Jython Function Name: sortMusic() Parameters: Name -string of artist’s name Write a function that finds the first letter of an artist’s name. Test Cases: >>>sortMusic(“Lizzo”) Lizzo starts with the letter L. >>>sortMusic(“Khalid”) Khalid starts with the letter K.
Using JES/Jython Function Name: approachAllAngles() Parameters: Sides- integer of how many sides the shape has Using...
Using JES/Jython Function Name: approachAllAngles() Parameters: Sides- integer of how many sides the shape has Using the formula, D = ((Number of sides - 2) * 180) / Number of sides write a function that takes in the number of sides in your polygon and prints a sentence containing the angle measurements and the number of sides in the polygon. Test Cases: >>>approachAllAngles(4) Each angle in a regular polygon with 4 sides measures 90 degrees. >>>approachAllAngles(9) Each angle in a...
Write a Scheme function that takes a simple list of numbers as a parameter and returns...
Write a Scheme function that takes a simple list of numbers as a parameter and returns a list with the largest and smallest numbers in the input list.
Write a Python function to count the number of even numbers from a list of numbers....
Write a Python function to count the number of even numbers from a list of numbers. Write a Python function that takes a list and returns a new list with unique elements of the first list. Sample List : [1,2,3,3,3,3,4,5] Unique List : [1, 2, 3, 4, 5]
5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive...
5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive numbers representing deposits to and negative numbers representing withdrawals from a bank account. Your function should return a list of two floating-point numbers; the first will be the sum of the deposits, and the second (a negative number) will be the sum of the withdrawals. >>> statement([30.95, -15.67, 45.56, -55.00, 43.78]) [120.29, -70.67]
Write a largestBelowValue(numbers, value) function that returns the largest number in the list numbers that is...
Write a largestBelowValue(numbers, value) function that returns the largest number in the list numbers that is smaller than value. Assume the numbers are always positive integers. Some example test cases (include these test cases in your program): >>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 40)) 31 >>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 41)) 40 returns None since no value is smaller than 2 in the list >>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 2)) None
Write a Python function count_bigger that takes two parameters, a nested list of objects and a...
Write a Python function count_bigger that takes two parameters, a nested list of objects and a threshold number. It returns an integer specifying how many of the objects anywhere in the nested list are numbers that are larger than the threshold. (For our purposes, "numbers" are either integers or floats.) There may be objects in the list other than numbers, in which case you would simply ignore them. Here are a couple of examples of how the function should behave...
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT