Question

Find the sum of two equal-number matrices. Example: First ask the user for the number of rows of the two matrices. 2 2 + 5 8phyton help please!!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

https://onlinegdb.com/BkjsGdyWv

n=int(input("Enter number of rows: "));
A=[];
for i in range(n):
s=str(input("Enter elements of matrix 1 in row "+str(i+1)+": "));
L=(s.split(" "));
V=[];
for i in range(len(L)):
V.append(int(L[i]));
A.append(V);
A1=[];
for i in range(n):
s=str(input("Enter elements of matrix 2 in row "+str(i+1)+": "));
L=(s.split(" "));
V=[];
for i in range(len(L)):
V.append(int(L[i]));
A1.append(V);
C=A;
for i in range(n):
for j in range(len(A[0])):
C[i][j]=A[i][j]+A1[i][j];
for i in range(n):
for j in range(len(A[0])):
print(A[i][j],end=" ");
if(i==0):
print("+ ",end="");
else:
print(" ",end="");
for j in range(len(A1[0])):
print(A1[i][j],end=" ");
if(i==0):
print("= ",end="");
else:
print(" ",end="");
for j in range(len(C[0])):
print(C[i][j],end=" ");
print("");
  

Add a comment
Know the answer?
Add Answer to:
phyton help please!!!!! Find the sum of two equal-number matrices. Example: First ask the user for...
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
  • python help please and thank you Find the sum of two equal-number integer matrices. Example: 2...

    python help please and thank you Find the sum of two equal-number integer matrices. Example: 2 2 + 5 8 = 7 10 5 4 4 10 9 14 First it asks the user for the number of rows of the two matrices. Then ask for the value of each of the rows of the two matrices, where each column of the row must be separated by a space (use the split function to convert the captured text to a...

  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • Write a method to multiply two matrices. The header of the method is: public static double[][]...

    Write a method to multiply two matrices. The header of the method is: public static double[][] multiplyMatrix(double[][] a, double[][] b) To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element is For example, for...

  • Write a MIPS program to that will take two 4x4 matrices, and calculate their sum and...

    Write a MIPS program to that will take two 4x4 matrices, and calculate their sum and product, using row major, and column major math (so this is actually 4 problems, but obviously they’re all pretty related). I generated two sample arrays to test 2   1       9       2 7   9       10      10 3   4       4       4 2   5       4       4 8 7 1 2 2 7 8 6 7 5 6 8 9 4 8 9 The output of your program...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • Please help me out with this assignment. Please read the requirements carefully. And in the main...

    Please help me out with this assignment. Please read the requirements carefully. And in the main function please cout the matrix done by different operations! Thanks a lot! For this homework exercise you will be exploring the implementation of matrix multiplication using C++ There are third party libraries that provide matrix multiplication, but for this homework you will be implementing your own class object and overloading some C+ operators to achieve matrix multiplication. 1. 10pts] Create a custom class called...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix...

    Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix algebra: A vector is a one-dimensional set of numbers, such as [42 9 20]. The dot product of two equal-length vectors A and B is computed by multiplying the first entry of A by the first entry of B, the second entry of A by the second entry of B, etc., and then summing these products. For example, the dot product of [42 9...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • In C# You will be prompting the user for a text string a list of bills...

    In C# You will be prompting the user for a text string a list of bills they have every month. a. This should be a comma separated list , bill1, bill2, bill3 b. Validate that this text string is not left blank. 3. Create a custom function called CreateBillArray a. This function should accept the string variable that holds the bills. b. Inside of the function, split the text string of the bills into a string array with each individual...

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