Question

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_

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

Below is the python solution with output screenshot

Note : I have also commented the code for better understanding

Code :

def print_matrix_char(matrix):
    # print the number of rows and column
    print("Number of rows:", len(matrix))
    print("Number of columns:", len(matrix[0]))
    # print the new line 
    print()
    print("\t", end="")
    # first print the upper line for columns
    for i in range(len(matrix[0])):
        print(i,end="\t")
    print()
    # print the matrix
    for i in range(len(matrix)):
        # print the row number
        print(i,end="\t")
        for j in range(len(matrix[0])):
            print(matrix[i][j],end = "\t")
        print()

if __name__ == "__main__":
    matrix = [['c', 'u', 'r', 'i'],
              ['z', 'y', 'c', 'x'],
              ['e', 'q', 'y', 'm']]
    print_matrix_char(matrix)

Note : for better formatting please refer to the code screenshot below

1 3 4 5 6 7 8 9 def print_matrix_char(matrix): # print the number of rows and column print(Number of rows:, len(matrix)) pr

Output :

C:\Users\lenovo\Desktop solution>python solution.py Number of rows: 3 Number of columns: 4 1 2 3 i C u r Z с х 1 2 у a e у m

Add a comment
Know the answer?
Add Answer to:
Using Python Programming Language: 4. Implement the following function in the PyDev module functions.py and test...
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
  • 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 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 Returns None. a 2D list of strings (2D list) w Sample testing: Number of rows: 3 Number of columns: 4 0 1 2 3 i 0 C u r 1 Z 2 Y...

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

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

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

  • The following must be coded using Python programming language: In this assignment you will implement two...

    The following must be coded using Python programming language: In this assignment you will implement two programs: a chat client and a server. The server will listen to a known port for new connections from clients. When a client connects, it will be able to authenticate with the server and then join a chat room and send messages.

  • Python Programming language Write the following functions: getNumInRange(prompt, min, max) - get...

    Python Programming language Write the following functions: getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt' calcAvg(values) - calculates and returns the average from a supplied list of numeric values menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this. getAlbum() - prompts the user for information to populate a dictionary representing...

  • Python Language. Question 5 Next, you are asked to implement a Python function called compareScoreStrings(), that...

    Python Language. Question 5 Next, you are asked to implement a Python function called compareScoreStrings(), that will take in the score strings for two players and analyze them, returning information comparing the two. The function specification you need to adhere to is given below. Note that you can assume scoreStringAnalysis () from the previous question has been implemented and you can call it if needed. def compareScoreStrings (pistring, p2string): Given score strings for two players, determine: - which player was...

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

  • My module page is correct but I don't believe I am using the main() function properly....

    My module page is correct but I don't believe I am using the main() function properly. One of my .py files is supposed to contain my definitions, which is the module file. My second .py file is supposed to properly call a main function that does what my program asks it to: First name, last name, age, and respond based off of input. For some reason I am struggling with using the main() function so that my program works. Any...

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