Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Know how to use reservations systems to inventory demand.

Answered: 1 week ago