# How would I solve this problem in python languageGradesa) Write a program that reads in the names and test grades of 5 students from the data file “grades.txt”. Use the split function to separate the names and test scores and convert the test scores to numeric values.b) Calculate the average of the test scores. c) Display the names, test scores and the average on the screen as follows:Name                      Grade ---------------------Mickey Mouse        90.0Jane Doe                50.0Minnie Mouse        95.0Donald Duck          80.0Daffy Duck  70.0Average Grade:     77.0d) Prompt the user for a new first name, last name and grade. e) Append the files “grades.txt” with the new data in the same format as the existing records.

Question
928 views

How would I solve this problem in python language

a) Write a program that reads in the names and test grades of 5 students from the data file “grades.txt”. Use the split function to separate the names and test scores and convert the test scores to numeric values.

b) Calculate the average of the test scores. c) Display the names, test scores and the average on the screen as follows:

Mickey Mouse        90.0

Jane Doe                50.0

Minnie Mouse        95.0

Donald Duck          80.0

Daffy Duck  70.0

d) Prompt the user for a new first name, last name and grade. e) Append the files “grades.txt” with the new data in the same format as the existing records.

check_circle

Step 1

Program Instructions:

• Use the open() function to read from the file.
• Save the result o spilt() function into a list and use that list to get names and grades.
• Use the sum() and len() function to calculate the average of the test scores.
• Use a for-each loop to print the result from lists.
• Take input from the user and use write() function to write in the file opened in append mode.
Step 2

Program:

name = []

print()

for line in file_name:

# split function to take values

values = line.split(" ")

first_last_name = values[0] + " " + values[1]

name.append(first_last_name)

# to calculate average

# to print the score

file_name.close()

print("---------------------")

for i in range(len(name)):

print()

print()

# to take user input

first_name = input("Enter first name:")

last_name = input("Enter last name:")

# to write in file

write_line = "\n"+first_name+" "+last_name+ " " + str(grade)

file_name1.write(write_line)

file_name1.close()

Step 3

Any “grades.txt” file can be used in place of the following “grades.txt&rdqu...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in