Question: Create test.py for code below. import fileinput import sys def studentData(lines): studentLogs = int(lines[0].strip()) students = {} for line in lines[1:]: studentID, actionCode, third, timestamp

Create test.py for code below.

import fileinput

import sys

def studentData(lines):

studentLogs = int(lines[0].strip())

students = {}

for line in lines[1:]:

studentID, actionCode, third, timestamp = line.strip().split()

studentID, third, timestamp = int(studentID), int(third), int(timestamp)

if studentID not in students:

students[studentID] = {

"pageOpen": set(),

"submissionScores": [],

"temperatureTracked": 0,

}

if actionCode == "P":

students[studentID]["pageOpen"].add(third)

elif actionCode == "S":

students[studentID]["submissionScores"].append(third)

elif actionCode == "T":

students[studentID]["temperatureTracked"] = timestamp

students = {

i: j for i, j in students.items() if j["pageOpen"] and j["submissionScores"]

}

values = []

for studentID, item in students.items():

lowestPageID = min(item["pageOpen"])

latestPageID = max(item["pageOpen"])

averageSubmissionScore = sum(item["submissionScores"]) / len(

item["submissionScores"]

)

values.append((studentID, lowestPageID, latestPageID, averageSubmissionScore))

values.sort(key=lambda x: (x[1], x[2], x[3]))

result = " ".join([f"{s[0]} {s[1]} {s[2]} {int(s[3])}" for s in values])

return result

if __name__ == "__main__":

filename = input()

with open(filename) as data_file:

lines = data_file.readlines()

print(studentData(lines))

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 Databases Questions!