Write a correct, well-structured, well-documented Python program to create a list of lists containing student information. You are to create one master list whose elements must be lists containing elements for the student’s first name, last name, major, credit hours completed, and quality points earned. (The organization of the master list will be similar to what you did in Lab 11.) The data must be read from a text file named “prog3.txt” in the default directory. Each line in this file contains the data for one student. Individual items of data on a line are separated by one or more spaces. The order of the data items on a line is guaranteed to be techid, first name, last name, major, credits, quality points. Once your master list is created, you should print it to demonstrate that it was created correctly. Then your program must iterate through the list and ask the user for end-of-the-semester updates. This will entail asking the number of credits completed and the number of quality points earned in this semester for each of your students. These numbers are then to be added to the values stored in the list and the updated values are to be stored back in the list. Once all of the updates are complete, print the master list again to demonstrate that you did the updates correctly. Finally, “disassemble” your master list into lines of text of the same format as those you read in and write them, line by line, to a text file called “out.txt” in the default directory. Your program must also meet the following design specifications. • You are allowed to use any string functions or methods that you wish. • You must put the code for your main program in a function named main. • You program must read its initial data from the file named prog3.txt in the default directory • You must have a function which has a single parameter, representing a line of text from the file. This function must the list of the information for that student. • Once the above function returns the list for a single student, you must then incorporate this list into your master list. • The update information must be entered from the keyboard and must be only the numbers for the current semester. (Do not ask the user for the total number of credits or quality points.) These input values must be added to the previously stored numbers and the totals must be stored back in the appropriate entries of your data structure. You should also display enough information about the student so the user knows which person is being asked about. • The final output file must be called out.txt in the default directory and must be formatted in the same manner as the original input file. This is the code i have so far which I can get the master list to print, having trouble with the adding and printing a new list. Please Help. emptyList =  def studentInf(file): file.readline() for line in file: line = line.strip() line = line.split(' ') emptyList.append(line) return emptyList newList =  def newList(emptyList) : for line in emptyList: techId = (line) firstName = (line) lastName = (line) credit = int(line) qPoint = int(line) reutrn(newList) def main(): file = open('Lab11.txt', 'rU') emptyList = studentInf(file) newList(emptyList) print file.close main() This program will print out a GPA for each Student using an input file. I am using this as a base to my program because the first function will create a list Which is my master list. What do I have to change in the next two functions to make it take each student 1 at a time from file and add more credit hours and quality points then create a new list with the updated credit hours and quality points. I also want all this to print to an outfile.
Jump to Post
Code tags are better when just the code is tagged. Still, better than no tags at all.
I don't see how the code you posted does anything at all. The lists are instantiated outside of the functions and in the case of newList(), not even used. Let's see what might …
All 3 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.