Matrix with Python
Read the questions and solve the problems.
We'll cover the following...
This project is designed with the purpose of inspecting the object-oriented and control flow concepts.
Challenging questions❓
Task 1: Read matrix from a file
The task is to read the matrix from a file. This task has some specifications. The file should follow a specific format. For example, you can have:
1 2 3
4 5 6
7 8 9
The format of the file is up to you. The above data can be mapped as:
Write a function read_matrix(filename)
, where the filename
is the name of the file containing the matrix. The function should read the file using the context manager protocol into a nested list. If we read the above file, we should get the list as: [[1, 2, 3], [4, 5, 6], [7, 8, 9]].
🧐 Note: Assume that data in the file is always a matrix.
That’s not ...
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy