Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

students = [\"Ernie\", \"Bert\", \"Elmo\", \"Oscar\", \"Grover\", \"Count von Co

ID: 3868164 • Letter: S

Question

students = ["Ernie", "Bert", "Elmo", "Oscar", "Grover", "Count von Count", "Cookie Monster"]
midterm = [22, 98, 65, 82, 63, 88, 70]
essay = [0, 95, 63, 45, 69, 77, 70]
final = [16, 99, 64, 79, 52, 66, 70]

-

Language: Python

Programs used: Processing 3.0

Purpose: Practice combining data from lists and writing it to tabular files. Degree of Difficulty: Easy For this problem, you will start with code that has several lists that contain data pertaining to student grades in a class. Your job is to write a program that will write the data in these lists to a tabular text file in a format as specified below. As with question 1, this is not an interactive program, so you won't need functions like draw() or setup() The data to write to file consists of four lists. The first list contains the names of all the students in the class. The other 3 lists contain a grade for each student for 3 different grade items: a midterm exam, arn essay, and a final exam (yes, this is one of those easy classes where the only coursework is a single essay) The grade data in these 3 lists matches the order of the list of student names, i.e. the first number in the midterm list is the midterm exam grade for the first student in the list of student names. On the Moodle you can download the file student_data.txt; you can copy/paste the list literals there into your Processing program to use as your testing data. It's just test data though: the code you write should work for a class with any number of students! You are, however, guaranteed that all 4 lists will always be the same length i.e. every student always has a grade for their midterm, essay and fina) Your code should print all of the data in the lists described above to an output file in the following format: . All of the data for one student should be printed on the same line » Data for each student should be printed in the following order and consists of student name, midterm grade, essay grade , final exam grade, student's final mark » Each item on the same line should be separated by a single comma. There should be no comma at the end of the line Note that the last item on each line, the student's final mark, isn't in any of the lists. Your code will have to calculate it based on the other grade items. The grading scheme for the class is: 20% midterm, 30% essay and 50% final. It is okay if the final grade is a floating point number Sample Output If we had the sample lists below: students = ["Big Bird", "Snuffleupagus"] midterm = [50, 0] essay = [70 , 0] final = [100, 0]

Explanation / Answer

def writeFile():
students = ["Ernie", "Bert", "Elmo", "Oscar", "Grover", "Count von Count", "Cookie Monster"]
midterm = [22, 98, 65, 82, 63, 88, 70]
essay = [0, 95, 63, 45, 69, 77, 70]
final = [16, 99, 64, 79, 52, 66, 70]
  
file = open('result.txt','w')
  
length = len(students)
for i in range(length):
str1 = students[i] +' '+ str(midterm[i]) +' '+ str(essay[i]) +' '+str(final[i])
file.write(str1)
file.write(' ')
file.close()

if __name__ == "__main__":
writeFile()