**Problem 1**

In this problem, you will input an unknown quantity of grades from a file and calculate the average.

a) Open the file `grades.txt` (provided on Moodle) for input.
b) Use a loop to process the file, as it contains an unknown number of lines.
c) Read in one grade at a time until no more grades are available:
1. Output the grade.
2. Add the grade to a sum.
3. Increment a counter.
d) When there are no more grades to read:
1. Close the file.
2. Output the average and number of grades as shown below.

**Example Output:**

```
Problem 1
97.3
94.6
86.5
82.8
88.0
75.6
Class Average is 87.5 for 6 students
```

---

**Problem 2**

In this problem, you will input an unknown quantity of student names and grades from a file and calculate the average.

a) Open the file `mixed.txt` (provided on Moodle) for input.
b) Use a loop to process the file, as it contains an unknown number of lines.
c) Read in one student name and grade at a time until no more grades are available:
1. Output the student name and grade.
2. Add the grade to a sum.
3. Increment a counter.
d) When there are no more grades to read:
1. Close the file.
2. Output the grade average and number of grades as shown below.

**Example Output:**

```
Problem 2
Sue 89.2
Jim 85.5
Andy 68.2
Val 98.0
Sri 99.5
Fran 63.5
Class Average is 84.1 for 6 students
```

---

**Problem 3**

In this problem, you will input an unknown quantity of student names and grades from a file and output students passing or failing the class.

a) Open the file `mbed.txt` (provided on Moodle) for input.
b) Open a file for output.
c) Output a line to the output file stating these are the students who passed the class.
d) Use a loop to read in one student name and grade at a time until no more grades are available:
1. If the grade is greater or equal to 70, output the student name and grade to the output file.
e) When there are no more grades to read, rewind the file.
f) Output a line to the output file stating these are the students who failed the class.
g) Use a loop to read in one student name and grade at a time until no more grades are available:
1. If the grade is less than 70, output the student name and grade to the output file.
h) When there are no more grades to read, close both the input and output files.

**Example Output to the File:**

```
Problem 3
The following students passed:
Sue 89.7
Jim 85.6
Val 98.0
Sri 99.5

The following students failed:
Andy 68.2
Fran 63.5
```

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