CODE IN PYTHON:
def my_max(a): if a: max = a[0] for val in a: if val > max : max = val return max print("List is empty") def my_min(a): if a: min = a[0] for val in a: if val < min : min = val return min print("List is empty") a = [0.28197719, 0.59580708, 0.54095388, 0.44264927, 0.12360858, 0.3067179, 0.33002426, 0.43553806, 0.14259775, 0.01909447] print(my_max(a)) print(my_min(a))
INDENTATION:
OUTPUT:
Problem 5 Given a list a, the max function in Python's standard library computes the largest...
Hem 1 def expo(base, exponent): # Write your function here Python's pow function returns the result of raising a number to a given power. Define a function expo that performs this task, and state its computational complexity using big-o notation. The first argument of this function is the number, and the second argument is the exponent (nonnegative numbers only) 4 def main(): ***Tests with powers of 2.*** for exponent in range (5): print(exponent, expo(2, exponent)) 000 9 if _name__ ==...
What would the function look like in MATLAB? Write a function called mysort that takes a 3-element vector as its sole arguments. It uses if statements, possibly nested, to return a 3-element vector with its elements in non-decreasing order, i.e., the first element in the returned vector equals the smallest element of the input vector and the last element equals the largest element in the input vector. NOTE: Your function should not use any built-in functions, e.g., sort, min, max,...
Question 1 You are given a list of product codes for dog sweaters sold by Sweaters 4 Fur Friends. The codes are all 5 digits long and the last two digits in each code represents the size of the corresponding sweater. Here is a sample of the list of codes: sweaterCodes = [12309, 32109, 54204, 35410, 87508, 50404, 94307, 94306, 54205, 12303, 32111, 32110] Write a Python program in a file called SortCodes.py to sort the list of codes into...
Rules: You may NOT use the following built-in functions. sort() sum() max() min() Except for format() all string methods are banned. Except for append() and extend() all list methods are banned. You may not import any module. Make sure to test your code with a variety of inputs. Do not assume the examples in these directions are reflective of the hidden test cases. Part 3 Echo (5 Points) Write a function called echo that takes as argument a list and...
Python. Write a function that takes in a list and returns the first nonzero entry. def nonzero(lst): """ Returns the first nonzero element of a list >>> nonzero([1, 2, 3]) 1 >>> nonzero([0, 1, 2]) 1 >>> nonzero([0, 0, 0, 0, 0, 0, 5, 0, 6]) 5 """ "*** YOUR CODE HERE ***"
PYTHON. Write the following functions without using any predefined functions unless specified. def min (dataList) : #returns the smallest value of the data values in dataList def max (dataList): #returns the largest value def getRange (dataList) def mean (dataList) : #returns the average of data values def median (dataList): #returns the middle value of an ordered list #note: to sort the list first, may use the predefined sort function Then write a test1 function to test the above functions using...
PLEASE USE F# PROGRAMMING LANGUAGE: NO LOOPS OR CORE LIBRARY FUNCTIONS. ONLY USE RECURSION. Problem 3 (10 pts) Define a function rev that takes a list xs and returns it in the reverse order. • F# standard library has List.rev, do not use it. You need to reimplement it. In [ ]: let rev (xs: 'a list) In [ ]: // Test you function List.rev [] = rev [] |> printfn "%" List.rev [1..9] = rev [1..9] |> printfn "%b'...
The purpose of this lab is to practice working with Python's higher order functions and ternary operator. Write all of your code in one file named lab2.py. You can write the code for items 1 through 6 directly inside the main function. Let a be the list of values produced by list(range(1, 11)). [1 point] Using the map function and a lambda argument, write an expression that produces a list of the cubes of the values in a. Assign the...
5: Problem 24 Previous Problem Problem List Next Problem (1 point) For the function whose graph is given below, list the following quantities in increasing order, from smallest to largest. a fie de B. fre) de ce fel de D. Jo se de Answer (use A, B, C, D, and separate by commas): Note: You can click on the graph to enlarge the image.
3. Write a function called sort3 that takes a 3-element vector as its sole arguments. It uses if-statements, possibly nested, to return the three elements of the vector as three scalar output-arguments in nondecreasino-roer , i.e., the first output argument equals the smallest element of the input vector and the last output argument equals the largest element. NOTE: Your function may NOT use any built-in functions, e.g., sort, min, max, median, etc. (5 points) (bonus question). Write a function called...