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
Asked Jun 11, 2019
928 views

How would I solve this problem in python language

Grades

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:

Name                      Grade ---------------------

Mickey Mouse        90.0

Jane Doe                50.0

Minnie Mouse        95.0

Donald Duck          80.0

Daffy Duck  70.0

Average Grade:     77.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

Expert Answer

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:

# to read from file

file_name = open("grades.txt")

name = []

grades = []

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)

  grades.append((float(values[2])))

# to calculate average

avg_test_score = sum(grades) / len(grades)

# to print the score

file_name.close()

print("Name\t\tGrade")

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

for i in range(len(name)):

  print(name[i],"\t",grades[i])

print()

print("Average Grade:\t",avg_test_score)

print()

# to take user input

first_name = input("Enter first name:")

last_name = input("Enter last name:")

grade = input("Enter grade:")

file_name1 = open("grades.txt","a")

# 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...

help_outline

Image Transcriptionclose

saved grades.txt Mickey Mouse 9e.e 1 2 Jane Doe 50.0 3 Minnie Mouse 95.0 4 Donald Duck 80.0 Daffy Duck 70. Ln

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

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

Engineering

Computer Engineering

Programing

Related Computer Engineering Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Ask the user to enter the month of the year (number 1 through 12): “Enter the month of the year - nu...

A: The algorithm for the program would be as below:Declare one int variable for accepting user inputPro...

question_answer

Q: What is the output of the following code? def test_func (*a) print (a[0]) test_func1,2,3,4) test fun...

A: Consider the given code:#Function definition test_func()def test_func(*a):    #Print the output    p...

question_answer

Q: Consider the client A sends the data of 12 bytes to the sender B using the UDP. What is the efficien...

A: Efficiency:In User Datagram Protocol (UDP), the formula for computing efficiency of the transmission...

question_answer

Q: this is a problem that I have how would I go about solving it? Stadium Seating There are three seati...

A: Algorithm: Include required header files.Define main function.Initializes the seat prices for class ...

question_answer

Q: How do I write a code that places my name in an email link? Thanks

A: As there is no particular programming language mentioned, we are doing this using HTML code.

question_answer

Q: Do you think technologies like Big Data and Predictive Analytics in Marketing would have worked 10-1...

A: The technologies like Big Data would not have worked 10-15 years back as due to lack of large datase...

question_answer

Q: Write a program to convert between KPH and MPH in either direction.If you are driving across the bor...

A: Click to see the answer

question_answer

Q: how can I create comments in python?

A: In python, # character is used to start the single line comments. Place a hash symbol in front of a ...

question_answer

Q: What are the mantissa and exponent values if 6.75 is represented in 8-bit binary floating-point repr...

A: Conversion of decimal to 8-bit floating point representation:Step 1: Convert the integer part of the...