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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started