Question

Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...

Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max.

Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000

Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002

Homework Answers

Answer #1


Refer to the function below which returns the maximum element from a list
Source code:
def my_max(lst):

max_val = lst[0]
for item in lst:
if item > max_val:

max_val = item
return max_val
result = my_max([-999000, -1000000, -2000000]); print(result)

Output screenshot:


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
python code Write the function definition for a function which accepts one value from the main...
python code Write the function definition for a function which accepts one value from the main program and prints three times the number that is sent to it. For example, if the program sent 8, the function would print 24.
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 the function definition for a function which accepts 2 values from the main program and...
Write the function definition for a function which accepts 2 values from the main program and returns the average of the two numbers. DO NOT WRITE AN ENTIRE PROGRAM. DO NOT WRITE THE STATEMENT THAT CALLS THE FUNCTION! JUST WRITE THE FUNCTION DEFINITION python program
Write a function called odd_rms that returns orms, which is the square root of the mean...
Write a function called odd_rms that returns orms, which is the square root of the mean of the squares of the first nn positive odd integers, where nn is a positive integer and is the only input argument. For example, if nn is 3, your function needs to compute and return the square root of the average of the numbers 1, 9, and 25. You may use built-in functions including, for example, sum and sqrt, except for the built-in function...
Write a function called odd_rms that returns orms, which is the square root of the mean...
Write a function called odd_rms that returns orms, which is the square root of the mean of the squares of the first nn positive odd integers, where nn is a positive integer and is the only input argument. For example, if nn is 3, your function needs to compute and return the square root of the average of the numbers 1, 9, and 25. You may use built-in functions including, for example, sum and sqrt, except for the built-in function...
Write a function reshaped_by_col(nums, col) which takes a Python list nums, and an integer value for...
Write a function reshaped_by_col(nums, col) which takes a Python list nums, and an integer value for columns that reshapes the 1D nums into col number of columns. Finally, returns the reshaped numpy array. If the shape cannot be reshaped, return None (you can do this without catching exceptions). For example: Test Result nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] col = 2 print(reshaped_by_col(nums, col)) [[ 10 20] [ 30 40] [ 50 60] [ 70...
Python Question: Write a function which returns the sum of squares of the integers 1 to...
Python Question: Write a function which returns the sum of squares of the integers 1 to n. For example, the sum of the squares from 1 to 4 is 1 + 4 + 9 + 16, or 30. You may choose what should be returned if n == 0 You may not use the built-in Python sum function. The Solution Must be recursive >>> sum_of_squares(1) 1 >>> sum_of_squares(4) 30 >>> sum_of_squares(8) # 64 + 49 + 36 + ... +...
Create a function which returns the number of odd integers in a list (python)
Create a function which returns the number of odd integers in a list (python)
Question2: The following function is supposed to receive a list of numbers and a number as...
Question2: The following function is supposed to receive a list of numbers and a number as the input parameters. The function finds all occurrences of number inside the list and removes them from the list and eventually returns the results. Do you think this function will work as expected? If yes, please mention and if no, please fix it. def function(listOfNumbers, number): for i in range(len(listOfNumbers)): if listOfNumbers[i]==number: listOfNumbers.remove(number) return listOfNumbers newList = function([3,4,1,3,4,7,8,1,2,3,4,6,8], 3) print("After removing the occurrences of...
Write a method called countChar which accepts a string parameter and a character parameter and returns...
Write a method called countChar which accepts a string parameter and a character parameter and returns an integer, that is: int countChar (String s, char c) This method should count the number of occurrences of the character c within the string s, and return the count to the caller. Also write a main method that tests countChar. All of the print statements and user interaction belong in the main method, not in countChar.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT