Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

What Is The Responsibility Of A Pharmacist?

Answered: 1 week ago

Question

Q.1. what is constitution? Q.2. key of the constitution?

Answered: 1 week ago

Question

Q.1. what is meant by federal system?

Answered: 1 week ago