Question: A function create_seating(file_name, rows, columns) that takes in a string which acts as a file name and two integers, the rows and columns of a

A function create_seating(file_name, rows, columns) that takes in a string which acts as a file name and two integers, the rows and columns of a resulting 2D list that you should return. The file contains student names, listed all on separate lines. You should take the student names and place them in the seats, filling an entire row before moving on to the next. If you reach the end of a file and there are no more seats, print "Not enough seats!", but still return the seating arrangement. For all empty seats, put an empty string. create_seating("students.txt", 2,3) [["Heidi", "Dylan", "Aaron"], ["Meredith", "Ben", ""]]

Assuming students.txt contained: Heidi Dylan Aaron Meredith Ben

def create_seating(file_name, rows, columns):

seats = []

file = open(file_name, 'r')

for i in range(rows):

row = [] for j in range(columns):

row.append(file.readline().strip(' '))

seats.append(row)

if len(file.readline()) != 0:

print("Not enough seats!")

return seats

Here is an review question and answer. Could you please go through every line and explain it please? I don't really understand the question and the process of adding the contents of the file to 2D list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!