Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def accept_array (list) : n = int(input( Enter the element : )) for i in range( 0 ,n): x = int(input()) list.append(x) def show_array

def accept_array(list): n = int(input("Enter the element : ")) for i in range(0,n): x = int(input()) list.append(x) def show_array(list): print("Array : ", list) def ternary_search(l,r,key,list): if (r >= 1): mid1 = l + int((r - 1) / 3) mid2 = r - int((r - 1) / 3) if (list[mid1] == key): return mid1 if (list[mid2] == key): return mid2 if (key < list[mid1]): r = mid1 - 1 elif (key > list[mid2]): l = mid2 + 1 else: r = mid - 1 l = mid2 + 1 return -1 def Main(): while True: print(" 1.Accept and Display 2.Ternary search 3. Exit") z = int(input("Enter your choice : ")) if (z == 3): print("You are exited") elif (z == 1): list = [] accept_array(list) show_array(list) elif (z == 2): key = int(input("Enter the number to be search : ")) l = 0 r = len(list) - 1 a = ternary_search(l, r, key, list) if a == -1: print("Not found") else: print("Found at index :",a) else: print("Wrong choice") Main() 

def Accept_matrix(M): print("Enter row and col :") r=int(input("Row= ")) c=int(input("col= ")) print("Enter the Elements: ") for i in range(r): A1=[] for j in range(c): A1.append(int(input())) M.append(A1) def Display_Matrix(M, r, c): for i in range(r): for j in range(c): print(M[i][j],end=" ") print() def addition_matrix(M1,M2,M3,r,c): for i in range(r): for j in range(c): M3[i][j]=M1[i][j]+M2[i][j] def substraction_Matrix(M1,M2,M3,r,c): for i in range(r): for j in range(c): M3[i][j]=M1[i][j]-M2[i][j] def Multiplication_Matrix(M1,M2,M,r1,c1,c2): for i in range(r1): for j in range(c2): for k in range(c1): M[i][j] += (M1[i][k] * M2[k][j]) def Transpose_Matrix(M,r,c,T): for i in range(c): for j in range(r): T[i][j]=M[j][i] def main(): while(1): print("\t1: Accept Matrix") print("\t2: Display Matrix") print("\t3: Addition of two matrices") print("\t4: Subtraction of two matrices") print("\t5: Multiplication of two matrices") print("\t6: Transpose of a matrix") print("\t7: EXIT") choice = int(input("Enter your choice : ")) M3=[] if (choice == 7): print("You Are Exited") break elif (choice == 1): M1=[] M2=[] print("1st Matrix: ") Accept_matrix(M1) r1=len(M1) c1=len(M1[0]) print("2st Matrix: ") Accept_matrix(M2) r2 = len(M2) c2 = len(M2[0]) elif (choice == 2): print("1st matrix: ") Display_Matrix(M1, r1, c1) print(" 2st matrix: ") Display_Matrix(M2, r2, c2) elif (choice == 3): if(r1==r2 and c1==c2): M3=[[0 for j in range(c1)] for i in range (r1)] addition_matrix(M1, M2, M3, r1, c2) Display_Matrix(M3, r1, c1) elif (choice == 4): if(r1==r2 and c1==c2): M3 = [[0 for j in range(c1)] for i in range(r1)] substraction_Matrix(M1, M2, M3, r1, c2) Display_Matrix(M3, r1, c1) elif (choice == 5): M4 = [] if (c1 == r2): M4 = [[0 for j in range(c2)] for i in range(r1)] Multiplication_Matrix(M1, M2, M4, r1, c1, c2) Display_Matrix(M4, r1, c2) else: print("you can't multiple these two matrix") elif (choice == 6): T1 = [] T2 = [] T1 = [[0 for j in range(r1)] for i in range(c1)] Transpose_Matrix(M1, r1, c1, T1) T2 = [[0 for j in range(r2)] for i in range(c2)] Transpose_Matrix(M2, r2, c2, T2) print("Transpose of 1st matrix: ") Display_Matrix(T1, c1, r1) print("Transpose of 2nd matrix: ") Display_Matrix(T2, c2, r2) else: print("Invalid choice") print("Please Enter a valid choice ") main() 

Algorithm and flowchart of both the code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

How would the Fed handle a liquidity crisis next Thursday?

Answered: 1 week ago

Question

9. What happens when price is below the equilibrium price? Why?

Answered: 1 week ago