Random Seats

  1. Suppose you have a file which lists students in the following format:
    
    102241035:黃瓊儀
    103321001:游思愉
    103321002:張仕達
    103321007:黃柏元
    103321008:張秝榕
    103321009:楊甄誼
    103321010:賴郁伶
    103321016:邱俊翔
    103321017:謝長霖
    103321019:鮑惟仁
    
    
  2. We want to arrange these students into a few seats, so we have a file in the following format, which designates the number of seats in each row:
    
    6
    5
    4
    5
    6
    
    
  3. Suppose we have already defined a class Student as follows:
    
    class Student:
        def __init__(self, n, id):
            self.name = n
            self.id = id
            self.seq = randrange(1000)
            # When an object is created, a random number is assigned to it
    
    
  4. Write a function readStudents() to read students data into a list.
  5. Write a function readSeatTable() to read the number of seats into a list.
  6. Write a function printStudents(list) to print out students in a list according to the number specified in the seats file. For example, for the file
    
    6
    5
    4
    5
    6
    
    
    it will print 6 students in the first row, 5 students in the second row, 4 students in the third row, and so on.
  7. You may test your program with this students file and this seats file.

Test your functions with the following main program:

def main():
    studentList = readStudents("students-26.txt")
    seatList = readSeatTable("seats-4.txt")
    printStudents(studentList, seatList)

The program may run as follows:

102241035:黃瓊儀 103321001:游思愉 103321002:張仕達 103321007:黃柏元
103321008:張秝榕 103321009:楊甄誼 103321010:賴郁伶 103321016:邱俊翔
103321017:謝長霖 103321019:鮑惟仁 103321021:胡瑋哲 103321022:陳冠銘
103321024:潘嘉玲 103321025:余正威 103321026:張寬宏 103321027:黃仲誼
103321029:王韋翔 103321030:陳政樺 103321032:曾冠迪 103321037:范均泓
103321038:吳怡蓓 103321042:詹雅惠 103321047:吳芠萱 103321049:陳思穎
103321050:周霈菱 103321063:吳嘉偉