Answer :
Each problem involving reading data from a file, processing it, and outputting results. The code for each of these problems will be in Python. Make sure you have the input files ("grades.txt", "mixed.txt", and "mbed.txt") in the same directory as the script.
Problem 1 - Calculating Average Grades:
# Problem 1
total = 0
count = 0
with open("grades.txt", "r") as file:
for line in file:
grade = float(line.strip())
print(grade)
total += grade
count += 1
average = total / count
print(f"Class Average is {average:.2f} for {count} students")
Problem 2 - Calculating Average Grades with Student Names:
# Problem 2
total = 0
count = 0
with open("mixed.txt", "r") as file:
for line in file:
name, grade = line.strip().split()
grade = float(grade)
print(f"{name} {grade}")
total += grade
count += 1
average = total / count
print(f"Class Average is {average:.2f} for {count} students")
Problem 3 - Separating Passing and Failing Students:
# Problem 3
passing_students = []
failing_students = []
with open("mbed.txt", "r") as input_file, open("output.txt", "w") as output_file:
output_file.write("These are the students who passed the class:\n")
for line in input_file:
name, grade = line.strip().split()
grade = float(grade)
if grade >= 70:
passing_students.append((name, grade))
output_file.write(f"{name} {grade}\n")
output_file.write("\nThese are the students who failed the class:\n")
input_file.seek(0) # Rewind the file
for line in input_file:
name, grade = line.strip().split()
grade = float(grade)
if grade < 70:
failing_students.append((name, grade))
output_file.write(f"{name} {grade}\n")
print("The following students passed:")
for name, grade in passing_students:
print(f"{name} {grade}")
print("\nThe following students failed:")
for name, grade in failing_students:
print(f"{name} {grade}")
Make sure to replace the example file names ("grades.txt", "mixed.txt", and "mbed.txt") with the actual file names you have. The code provided reads the input files, processes the data as per the problem statements, and outputs the results as described.
Learn more about Python script click;
https://brainly.com/question/14378173
#SPJ4