Chegg Ans
Chegg Ans
Chegg Ans
Expert-verified
1st step
All steps
Answer only
o Step 1
To solve this problem, we need to compare the grades in the student records
with the grades defined in the "grades.csv" file. We can follow these steps:
1. Read the "grades.csv" file and store the grade ranges and corresponding
grades in a data structure, such as a dictionary or a list of tuples.
2. Iterate over the files in the students' directory.
3. For each student file, read the CSV file and extract the subject, marks, and
grades for each record.
4. Compare each grade in the student record with the corresponding grade range
from the "grades.csv" file.
5. If the grade in the student record is different from the expected grade based on
the grade range, record the tampered grade, actual grade, subject, and student
ID.
6. Write the tampered records to a new CSV file.
o Step 2
Here is the implementation in Python:
import os
import csv
Explanation:
This code assumes that the "Grades" directory and the "Students" directory are
in the same directory as the script. It also assumes that the output CSV file will
be named "TamperedRecords.csv" and will be created in the same directory as
the script.
You can run this code with the provided input files to obtain the desired output.
o Answer
Sample run:
grades.csv:
Marks,Grades
0-40,F
41-60,D
61-75,C
76-90,B
91-100,A
student1.csv:
Subject,Marks,Grades
Math,85,B
English,55,F
Science,92,A
student2.csv:
Subject,Marks,Grades
Math,60,C
English,78,B
Science,45,F
After running the code, the "TamperedRecords.csv" file will be created with the
following contents:
This indicates that for student1, the grade for the subject "English" was tampered
from "F" to "D" based on the actual grade range. Similarly, for student2, the
grade for the subject "Science" was tampered from "F" to "D" based on the actual
grade range.
Please note that the sample run assumes that the code is executed with the
provided input files in the appropriate directory structure.