Question

FOR PYTHON: Write a function findMinRow() that takes a two-dimensional list of numbers as a parameter. It returns the index of the minimum row in the list. The minimum row is the row with the smallest sum of elements. If the list has multiple rows that achieve the minimum value, the last such row should be returned. If the list is empty the function should return -1. The following shows several sample runs of the function:

Python 3.4.1 Shell File Edit Shel Debug Options Windows Help > findNinRow([]) >>> findMinRow([[4.1, 12.5, 8.4 0, -3,5, 711) >>> findHinRow(I4.1, 12.5, 8.4], 0], 3, 5, 7]1) >>findMinRow([[1, 2, 31, [-100 [10, -30.511) >>> findMinRow(II10, 201, [100, 200], [8, 7, 6, 5, [13, [8, 9, 1011) Ln: 56 Col: 4

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def poly(lst, x):
    "Input: List(int);  Output: int"
    res = 0
    for n,b in enumerate(lst):
        res += b*x**n
    return res

def countEvens(lst):
    "Input:List(int); Output: Int"
    evens = []
    newList = []
    counter = 0
    for x in lst:
        newList = newList + x
    for y in newList:
        if y % 2 == 0:
            evens.append(y)
    for z in evens:
        counter = counter + 1
    return counter

def findMinRow(lst):
    "Input: List(int); Output: int"
    return min(range(len(lst)), key=lambda i: sum(lst[i]))

def findMaxDiff(lst):
    "Input:list(int); Output: (int, int)"
    answer = []
    index =  max(range(len(lst)), key=lambda i: sum(lst[i]))
    holder = enumerate(max(x) - min(x) for x in lst)
    return max(x[::-1] for x in holder)
    return index


# Problem number 5 I wrote 2 functions: Begin problem 5:

def term(n):
    return 4 / (2.0 * n + 1) * (-1) ** n
def approx_pi(z):
    "Input: Float; output: Float"
    ind = term(0) 
    ind2 = term(0) + term(1)
    n = 2
    while abs(ind - ind2) > z:
        ind = ind2
        ind2 += term(n)
        n += 1
    return ind2
# end of problem 5


##
##>>> 
##>>> countEvens([[1,4,3],[12,0,7,10],[13]])
##4
##>>> countEvens([[25, -4],[1,2,3,4,5],[0,50,99]])
##5
##>>> countEvens([[1,3], [5]])
##0
##>>> countEvens([[]])
##0
##>>> findMinRow([[3.99, -12.5, 8.61], [0], [-30.5,8]])
##2
##>>> findMinRow([[3.99, -12.5, 8.61], [0], [-30.5,8]])
##2
##>>> findMinRow([[1,2,3], [-100], [10,-30.5,8]])
##1
##>>> findMinRow([[10,20], [100,200], [13], [8,9,10],[10,-30.5,8]])
##4
##>>> findMinRow([[10,20], [100,200], [13], [8,7,6,5],[8,9,10]])
##2
##>>> findMinRow([[10,20], [100,200], [8,7,6,5], [13], [8,9,10]])
##3
##>>> ================================ RESTART ================================
##>>> 
##>>> findMaxDiff([[12,3,50,17], [10,5,9,100,31],[5,3,1]])
##(95, 1)
##>>> findMaxDiff([[12,3,50,17],[10,5,9,1,31],[5,3,1]])
##(47, 0)
##>>> findMaxDiff([[1], [2],[3]])
##(0, 2)
##
##>>> approx_pi(0.5)
##3.3396825396825403
##>>> approx_pi(0.5)
##3.3396825396825403
##>>> approx_pi(0.05)
##3.1659792728432157
##>>> approx_pi(0.005)
##3.144086415298761
##>>> approx_pi(0.0000005)
##3.1415929035895926
##>>> poly([1,2,1],2)
##9
##>>> poly([1,0,1,0,1],2)
##21
##>>> poly([1,0,1,0,1],3)
##91
##>>> 
Add a comment
Know the answer?
Add Answer to:
FOR PYTHON: Write a function findMinRow() that takes a two-dimensional list of numbers as a parameter....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function called find_max that takes a two-dimensional list as a parameter and returns the...

    Write a function called find_max that takes a two-dimensional list as a parameter and returns the number of the row that sums to the greatest value. For example, if you had the following list of lists: list = [[1, 2, 3], [2, 3, 3], [1, 3, 3]] The first row would be 6, the second 8 and the third 7. The function would, therefore, return 1. You can assume the passed in list of lists has at least one row...

  • In Python, Complete the extraCreditTotal() function to take a list of grades as a parameter and...

    In Python, Complete the extraCreditTotal() function to take a list of grades as a parameter and return the total number points above 100. Examples: extraCreditTotal( [101, 83, 107, 90] ) returns 8 (because 1 + 0 + 7 + 0 is 8) extraCreditTotal( [89, 113, 95] ) returns 13 extraCreditTotal( [89, 73, 96, 97, 99, 100] ) returns 0

  • PYTHON CODE In a program, write a function that accepts two arguments: a list, and a...

    PYTHON CODE In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n. Output should look like: Number: 5 List of numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] List of numbers that are larger than 5: [6, 7, 8, 9, 10]

  • Write a python function alt which takes a list of strings myList as a parameter. alt...

    Write a python function alt which takes a list of strings myList as a parameter. alt then returns two strings s1 and s2 as a tuple (s1, s2). Here s1 is the concatenation of the strings in myList in even index positions, and s2 is the concatenation of the strings in myList in odd index positions. (List starts at index 0) For example, if myList = [‘My’, ‘kingdom’, ‘for’, ‘a’ , ‘horse’], then s1 = ‘Myforhorse’ and s2 = ‘kingdoma’.

  • in python: Write a program that uses a two-dimensional list that has 4 rows, with 5...

    in python: Write a program that uses a two-dimensional list that has 4 rows, with 5 columns in each row. The program should do the following things 1. Create or fill in the list so that it has random numbers between 0 and 50. 2. Print the entire list using a loop.

  • solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as...

    solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as a parameter and returns the count of strings that have at least the length of second parameter passed into the function that are found in the list. Recall that you can determine whether an item is a string by writing type(item) == str. The only list functions you are allowed to use are len(), indexing (lst[i] for an integer i), or slicing (lst[i:j] for...

  • Python. Write a function that takes in a list and returns the first nonzero entry. def...

    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 ***"

  • IN PYTHON: Write a function that takes, as arguments, two lists, one of which is a...

    IN PYTHON: Write a function that takes, as arguments, two lists, one of which is a character list and the other is the corresponding frequencies, and sorts the characters in ascending order of frequencies. The function should return a list consististing of two lists: the first list is the list of characters and the second is the list of corresponding frequencies, consistent with the rearranged characters. Name this function sortCharacters(characterList, frequencyList). For example, >>>sortCharacters(["a", "b", "c", "d"], [5, 8, 3,...

  • Write a function to find the smallest odd number in a list. The function takes a...

    Write a function to find the smallest odd number in a list. The function takes a list of numbers (each number is greater than or equal to 0) as an input. The function outputs a tuple, where the first number in the tuple is the smallest odd number and the second number in the tuple is the number of occurrences of that number. For example, if the input is [1, 4, 7, 3, 5, 2, 1, 3, 6] then the...

  • Write a Python function fun8(k) that gets list of strings k as passwords and returns the...

    Write a Python function fun8(k) that gets list of strings k as passwords and returns the valid passwords in list format. Criteria for checking passwords: 1.) At least 1 letter between [a-z] 2.) At least 1 letter between [A-Z] 3.) At least 1 number between [0-9] 4.) At least 1 character from [$#@] 5.) Minimum length of transaction password: 6 6.) Maximum length of transaction password: 12 7.) No spaces Example: >>>lst=["ABd1234@1", "a F1#,2w3E*", "2We3345"] >>>fun8(lst) [ABd1234@1] *****We are a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT