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

Questions Write a separate Python program for each of the following functions, d

ID: 3805350 • Letter: Q

Question

Questions Write a separate Python program for each of the following functions, described in more detail further in this document Function Signature Argument Types T Prints Returns a one Run (n n: int int b experimenter (n, range) Minimum None Maximum, Average (see example below) TC merge (list 1, list 2) listi: list, list2: list list d char Freq (infilepath) infilepaths str character None histogram e output Grid (x) multiplicative grid (see example list f primes (x) x: int g matrix Multiply (m1, m2) m1: 2D list, m2: 2D list 2D list

Explanation / Answer

Min/Max/average

#------------------------------------------------------------------------

L=[3, 6, 9, 12, 5, 3, 2]

print "max --> ", max(L)

print "min --> ", min(L)

print "Average : ", sum(L)/len(L)

Merge lists

#------------------------------------------------------------------------

L1=[3, 6, 9]

L2=[12, 5, 3, 2]

L3=L1+L2

print "L1 = ",L1

print "L2 = ",L2

print "L3 = ",L3

#character histogram
from collections import OrderedDict
import string

def count(s):
histogram = OrderedDict((c,0) for c in string.lowercase)
for c in s:
if c in string.letters:
histogram[c.lower()] += 1
return histogram

for letter, c in count('parrot').iteritems():
print '{}:{}'.format(letter, c)
#output grid

#Generate rows with length of 3
for row in range(3):
# Appen a blank list to each row cell
board.append([])
for column in range(3):
# Assign x to each row
board[row].append('x')

# Function will print board like an actual board
def print_board(board):
for row in board:
print " ".join(row)

print_board(board)

Check weather a number is prime of not:

#------------------------------------------------------------------------

n = input("Enter a No: ")

f=0

for i in range(2,n/2+1):

if n % i == 0:

f=1

break

if f==0:

print "Prime"

else:

print "Not Prime"

# Python Program - Matrix Multiplication
      
matrix1 = [[1, 2, 3],
   [4, 5, 6],
   [7, 8, 9]]
matrix2 = [[10, 11, 12, 13],
   [14, 15, 16, 17],
   [18, 19, 20, 21]]
rmatrix = [[0, 0, 0, 0],
   [0, 0, 0, 0],
   [0, 0, 0, 0]]
for i in range(len(matrix1)):
   for j in range(len(matrix2[0])):
       for k in range(len(matrix2)):
           rmatrix[i][j] += matrix1[i][k] * matrix2[k][j]

          
for r in rmatrix:
   print(r)