Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Use the Design Recipe to write a function called countEvensNxN that consumes a

ID: 3599436 • Letter: 1

Question

1.Use the Design Recipe to write a function called countEvensNxN that consumes a nested list representing a matrix of size N x N. The function returns the number of even numbers in the matrix. Note: You may assume the list argument passed to the function is a nested list.

2.Use the Design Recipe to write the function diagonal_diff which consumes an N x N matrix of numbers (nested list). and calculates the absolute difference between the sums of its diagonals.

3.Use the Design Recipe to write a function, mask_encode, that takes a list of booleans and a string and returns the characters from the string whose position is True in the list of booleans. It is possible that the list of booleans is longer than the string.

4. Use the Design Recipe to write a function, total_strange_caps, that take a list of words (strings) and returns the total number of capital letters that appear in positions other than the beginning of a word. You must break this problem into a sub-problem by first writing a function count_strange_caps that takes a single word and returns the number of capital letters that appear in positions other than the beginning of the word. You must then use this function in your total_strange_caps function. You need to use either the isupper() or islower() method of a string. Note: if the hidden test case is failing you need to make sure you are only using 2 loop statements total.

All the problems are in Python Please do NOT use# to explain, I only need the final correct answer. Thank you!

Explanation / Answer

def countEvens(matrix):
count = 0
for row in matrix:
for cell in row:
if cell % 2 == 0:
count += 1
return count

def diagonal_diff(matrix):
main_sum = 0
secondry_sum = 0
n = len(matrix)
for i in range(n):
main_sum += matrix[i][i]
secondry_sum += matrix[i][n - 1 - i]
return abs(main_sum - secondry_sum)

def mask_encde(bool_list, string):
result = ""
for i in range(len(string)):
if bool_list[i]:
result += string[i]
return result

def count_strange_caps(word):
count = 0
for i in range(1, len(word)):
if word[i].isupper():
count += 1
return count

def total_strange_caps(words):
total_count = 0
for word in words:
total_count += count_strange_caps(word)
return total_count
  

# copy pastable code: https://paste.ee/p/8QfUI

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote