Question

Implement the following function in the PyDev module functions.py and test it from a PyDev module named t04.py: def print_mat

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

#Python Code:-

# Method to print 2d list of string
def print_matrix_char(matrix):
  
# Store Number of rows
row=len(matrix)
  
# Store Number of columns
col=0
  
# Calculate number of columns
for i in range(0,len(matrix)):
for j in matrix[i]:
col+=1
break

print("Number of rows : ",row)
print("Number of columns: ",col)
  
#Print the 2d list in desired format.
print(" ",end=" ")
for i in range(0,col):
print(i,end=" ")
print()
  
for i in range(0,row):
print(i,end=" ")
for j in range(0,col):
print(matrix[i][j],end=" ")
print()
  
def main():
# 2d list of string
matrix=["curi","zycx","eqym"]
# Calling method to print the list.
print_matrix_char(matrix)
  
if __name__=="__main__":
main()
  
  
  

main.py 1 # Method to print 2d list of string 2. def print_matrix_char(matrix): # Store Number of rows row=len(matrix) # Stor

Output:

input > 5 3 4 Number of rows Number of columns: 0 1 2 3 0 i 1 у 2 Ym с u r N с x e ... Program finished with exit code 0 Pres

Add a comment
Know the answer?
Add Answer to:
Implement the following function in the PyDev module functions.py and test it from a PyDev module...
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
  • Using Python Programming Language: 4. Implement the following function in the PyDev module functions.py and test...

    Using Python Programming Language: 4. Implement the following function in the PyDev module functions.py and test it from a PyDev module named t04.py: def print_matrix_char(matrix): Prints the contents of a 2D list of strings in a formatted table. Prints row and column headings. Use: print_matrix_char (matrix) Parameters: matrix - a 2D list of strings (2D list) Returns: None. Sample testing: Number of rows: 3 Number of columns: 4 0 1 2 3 i 0 с u r 1 с у...

  • Implement the following function in the PyDev module functions.py and test it from a PyDev module...

    Implement the following function in the PyDev module functions.py and test it from a PyDev module named t15.py: def matrix_equal (matrixi, matrix2): i.e. have the Compares two matrices to see if they are equal same contents in the same locations. Use: equal matrix_equal (matrix1, matrix2) Parameters: matrix1 the first matrix (2D list of ?) matrix2 the second matrix (2D list of ?) Returns: equal True if matrix and matrix2 are equal, False otherwise (boolean) NMN Sample testing First matrix: 0...

  • 11. Implement the following function in the PyDev module functions.py and test it from a PyDev...

    11. Implement the following function in the PyDev module functions.py and test it from a PyDev module named t11.py: def find_word_vertical(matrix, word): Look for word in each column of the given matrix of characters. Returns a list of indexes of all column that are equal to word. Returns an empty list if no column is equal to word. Use: cols - find_word_vertical(matrix, word) Parameters: matrix - the matrix of characters (2D list of str) word - the word to search...

  • Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns...

    Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns all the items of each list concatenated together into one new 1D list. For example: flatten ([["a", "b"],["c","0"],["e","f"]]) would return ["a", "b","C","d", "e","f"] Save the function in a PyDev library module named functions.py Write a program t03.py that tests flatten function and prints the returned flat list to the screen. Test your program with a different list, hardcoded in t03.py • Copy the results...

  • PYTHON 3: An n x n matrix forms a magic square if the following conditions are...

    PYTHON 3: An n x n matrix forms a magic square if the following conditions are met: 1. The elements of the matrix are numbers 1,2,3, ..., n2 2. The sum of the elements in each row, in each column and in the two diagonals is the same value. Question: Complete the function that tets if the given matrix m forms a magic square. def is_square(m): '''2d-list => bool Return True if m is a square matrix, otherwise return False...

  • Create a class called Lab7b and in it implement all of the methods below. Also, write...

    Create a class called Lab7b and in it implement all of the methods below. Also, write a main method with test calls to all of these methods. Don’t forget to turn in your file to Canvas before the end of the lab today. int[][] random(int N, int start, int end) returns an N-by-N matrix of random integers ranging from start to end; int rowSum(int[][] a, int i) returns the sum of the elements in row i of the 2-D array...

  • For this lab, you will work with two-dimensional lists in Python. Do the following: Write a...

    For this lab, you will work with two-dimensional lists in Python. Do the following: Write a function that returns the sum of all the elements in a specified column in a matrix using the following header: def sumColumn(matrix, columnIndex) Write a function display() that displays the elements in a matrix row by row, where the values in each row are displayed on a separate line. Use a single space to separate different values. Sample output from this function when it...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • 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...

  • 11.3 (Subclasses of Account) In Programming Exercise 9.7, the Account class was defined to model a...

    11.3 (Subclasses of Account) In Programming Exercise 9.7, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and with- draw funds. Create two subclasses for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Draw the UML diagram for the classes and implement them. Write a test program that creates objects of...

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