Hello I need help fixing lines 16 and line 41. I'm not sure how to fix an UnsupportedOperation error. Here are the instructions: You must have a function that accepts three test scores and returns the float average You will calculate the average for an unknown number of students, by reading the data from a file named scores.txt. You must print the students’ average scores to the screen as shown above You must write the specified output to a file named grades.txt You may not use any global variables

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello I need help fixing lines 16 and line 41. I'm not sure how to fix an UnsupportedOperation error.

Here are the instructions:

  • You must have a function that accepts three test scores and returns the float average
  • You will calculate the average for an unknown number of students, by reading the data from a file named scores.txt.
  • You must print the students’ average scores to the screen as shown above
  • You must write the specified output to a file named grades.txt
  • You may not use any global variables
The input will come from a text file named scores.txt, which consists of multiple sets of a student ID
number followed by three test scores. The contents of a file containing the scores of four students are
shown below (the student ID number is of the form MXX where XX is a two-digit number):
M01
76
89
82
M02
91
81
83
M03
92
93
M02 85.00
M03 91.67
M04 88.33
90
M04
86
88
91
The output of the above data to the screen will be of the following form (note: 2 decimal places):
Student M01 average is 82.33
Student M02 average is 85.00
Student M03 average is 91.67
Student M04 average is 88.33
Only the student ID number and average score (separated by a space and formatted to 2 decimal places)
are written to the output file:
M01 82.33
Transcribed Image Text:The input will come from a text file named scores.txt, which consists of multiple sets of a student ID number followed by three test scores. The contents of a file containing the scores of four students are shown below (the student ID number is of the form MXX where XX is a two-digit number): M01 76 89 82 M02 91 81 83 M03 92 93 M02 85.00 M03 91.67 M04 88.33 90 M04 86 88 91 The output of the above data to the screen will be of the following form (note: 2 decimal places): Student M01 average is 82.33 Student M02 average is 85.00 Student M03 average is 91.67 Student M04 average is 88.33 Only the student ID number and average score (separated by a space and formatted to 2 decimal places) are written to the output file: M01 82.33
6 def calc_average (scorel, score2, score3):
7
n = 0
8
9
10
11
12
B 14 15 16 17 18 19 28 21 22 23 24 25 26 27 28 298128343567839 48 1 2 3 4 45 45
13
20
30
40
41
42
43
44
def
46
read_file
out_file =
for i in range (n):
out_file.write(str(n))
out_file.write("\n")
out_file.close()
inFile =
open("grades.txt", "w")
line = inFile.readlines ()
count = 0
str(input("Enter the name of the file to which the final results can be read:"))
open("scores.txt",
"r")
avg_total = 0
=
for i in range(n):
score2
student = input("Name: ")
count + 1
score1
= 0
= 0
score3 = 0
int(line)
avg_total
print (name, avg_total)
inFile.close()
main ():
file_name
45 main()
student =
return avg_total
i = 0
=
=
student_count = 0
str(input ("Enter the name of the file to which results should've been written: "))
while student_count !=
score1 = 0
score2 = 0
1
score3 = 0
student_count +=1
avg_total calc_average (scorel, score2, score3)
print('Student', student, 'average', avg_total)
=
Transcribed Image Text:6 def calc_average (scorel, score2, score3): 7 n = 0 8 9 10 11 12 B 14 15 16 17 18 19 28 21 22 23 24 25 26 27 28 298128343567839 48 1 2 3 4 45 45 13 20 30 40 41 42 43 44 def 46 read_file out_file = for i in range (n): out_file.write(str(n)) out_file.write("\n") out_file.close() inFile = open("grades.txt", "w") line = inFile.readlines () count = 0 str(input("Enter the name of the file to which the final results can be read:")) open("scores.txt", "r") avg_total = 0 = for i in range(n): score2 student = input("Name: ") count + 1 score1 = 0 = 0 score3 = 0 int(line) avg_total print (name, avg_total) inFile.close() main (): file_name 45 main() student = return avg_total i = 0 = = student_count = 0 str(input ("Enter the name of the file to which results should've been written: ")) while student_count != score1 = 0 score2 = 0 1 score3 = 0 student_count +=1 avg_total calc_average (scorel, score2, score3) print('Student', student, 'average', avg_total) =
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Hello i can see the output in the terminal but nothing appears in grades.txt

This is a Python script designed to calculate and record the average scores of students. Below is a step-by-step explanation of the code:

1. **Function Definition - `calc_average`:**
   - The function `calc_average` takes three arguments: `score1`, `score2`, and `score3`.
   - It returns the average of these three scores by summing them up and dividing by 3.

2. **Main Function - `main()`:**
   - User Input: 
     - Prompts the user to input the name of a file to read (`scores.txt`) and another file to write output data to.
   - File Handling:
     - Opens the specified `scores.txt` file for reading scores data.
     - Opens the specified output file (`grades`) for writing the calculated averages.
   - Data Processing:
     - Reads all lines from the input file `scores.txt`.
     - Splits data by newline characters into a list `data1`.
     - Checks if the total number of elements in `data1` is a multiple of 4. Adjusts the `length` accordingly if not.
   - Loop to Calculate Averages:
     - Iterates over the list `data1` in steps of 4.
     - Extracts student number and three scores.
     - Converts these scores from string to integer.
     - Calls `calc_average` to compute the average score for each student.
     - Prints the student number and average with formatting.
     - Writes the formatted string into the output file.

3. **Execution:**
   - The `main()` function is called to execute the program.

This script reads student scores from a file, calculates their average, and writes the results to another file. It uses basic file operations and employs list manipulation and looping for data processing.
Transcribed Image Text:This is a Python script designed to calculate and record the average scores of students. Below is a step-by-step explanation of the code: 1. **Function Definition - `calc_average`:** - The function `calc_average` takes three arguments: `score1`, `score2`, and `score3`. - It returns the average of these three scores by summing them up and dividing by 3. 2. **Main Function - `main()`:** - User Input: - Prompts the user to input the name of a file to read (`scores.txt`) and another file to write output data to. - File Handling: - Opens the specified `scores.txt` file for reading scores data. - Opens the specified output file (`grades`) for writing the calculated averages. - Data Processing: - Reads all lines from the input file `scores.txt`. - Splits data by newline characters into a list `data1`. - Checks if the total number of elements in `data1` is a multiple of 4. Adjusts the `length` accordingly if not. - Loop to Calculate Averages: - Iterates over the list `data1` in steps of 4. - Extracts student number and three scores. - Converts these scores from string to integer. - Calls `calc_average` to compute the average score for each student. - Prints the student number and average with formatting. - Writes the formatted string into the output file. 3. **Execution:** - The `main()` function is called to execute the program. This script reads student scores from a file, calculates their average, and writes the results to another file. It uses basic file operations and employs list manipulation and looping for data processing.
The image contains a slide titled "Different Biological Molecules" that outlines the main categories of biological molecules and provides specific examples for each. Below is a transcription of the content and an explanation of the diagram provided:

---

## Different Biological Molecules

### 1. **Carbohydrates**
- **Monosaccharides:** Glucose, Fructose
- **Disaccharides:** Sucrose, Lactose
- **Polysaccharides:** Starch, Cellulose

### 2. **Lipids**
- **Fats:** Triglycerides
- **Steroids:** Cholesterol
- **Phospholipids:** Phosphatidylcholine

### 3. **Proteins**
- **Enzymes:** Amylase
- **Structural Proteins:** Keratin, Collagen
- **Transport Proteins:** Hemoglobin

### 4. **Nucleic Acids**
- **DNA:** Deoxyribonucleic Acid
- **RNA:** Ribonucleic Acid

---

### Diagram Explanation

The diagram in the center visually categorizes each type of biological molecule. It uses brackets to group examples under each molecule category. Each bracket leads to specific examples, visually identifying the organization of these molecules based on their structural and functional characteristics.

Understanding these categories and their examples helps in appreciating the complexity and functionality of biological systems.
Transcribed Image Text:The image contains a slide titled "Different Biological Molecules" that outlines the main categories of biological molecules and provides specific examples for each. Below is a transcription of the content and an explanation of the diagram provided: --- ## Different Biological Molecules ### 1. **Carbohydrates** - **Monosaccharides:** Glucose, Fructose - **Disaccharides:** Sucrose, Lactose - **Polysaccharides:** Starch, Cellulose ### 2. **Lipids** - **Fats:** Triglycerides - **Steroids:** Cholesterol - **Phospholipids:** Phosphatidylcholine ### 3. **Proteins** - **Enzymes:** Amylase - **Structural Proteins:** Keratin, Collagen - **Transport Proteins:** Hemoglobin ### 4. **Nucleic Acids** - **DNA:** Deoxyribonucleic Acid - **RNA:** Ribonucleic Acid --- ### Diagram Explanation The diagram in the center visually categorizes each type of biological molecule. It uses brackets to group examples under each molecule category. Each bracket leads to specific examples, visually identifying the organization of these molecules based on their structural and functional characteristics. Understanding these categories and their examples helps in appreciating the complexity and functionality of biological systems.
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education