Question: Problem Four . Write a Python program that lets the user specify the number of rows and also specify the number of columns for a
Problem Four. Write a Python program that lets the user specify the number of rows and also specify the number of columns for a matrix. Then let the user enter floating point numbers, one by one, to put into this matrix, filling it up the way you read a book. Get the numbers from the user, one by one, for the top row, then for the next row, and so on. Then, after filling up the matrix, display the matrix in the usual, mathematical way, i.e. as a table of numbers. This problem does not involve files. Of course the matrix you create in the program will really be a list of lists of floating point numbers. Hint: Studying the solution to the class exercise might help you think about how to nest two loops for this purpose see posted announcement or email.
Hint: Here is the solution to the class exercise from the other day. Although Problem Four does not involve files, the way I want you to deal with building lists of lists is similar.
my_file = open("data.txt", "r") rows = my_file.readlines() matrix = [] number_of_rows = len(rows) for i in range(number_of_rows): text_row = rows[i].split(' ') number_of_columns = len(text_row) float_row = [] for j in range(number_of_columns): x = float(text_row[j]) float_row.append(x) matrix.append(float_row) print(matrix) Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
