Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wrote the following code: def write_students(): outfile = open(students.txt,'w') student_name= input(Enter student name;enter quit to stop: ) while student_name!= 'quit': major = input(Enter major:

I wrote the following code:

def write_students():

outfile = open("students.txt",'w')

student_name= input("Enter student name;enter quit to stop: ")

while student_name!= 'quit':

major = input("Enter major: ")

gpa = input("Enter gpa: ")

outfile.write(student_name + ' ')

outfile.write(major + ' ')

outfile.write(gpa + ' ')

student_name= input("Enter student name;enter quit to stop: ")

outfile.close()

def read_students(major):

infile = open("students.txt",'r')

line= infile.readlines()

maximum = 0

for line in infile:

l = line.strip().split()

if l[1] == major:

maximum = max(maximum,float(l[2]))

infile.close

def main():

write_students()

major = input("Enter major: ")

max_gpa = read_students(major)

print("The highest GPA for" , major , "majors is " ,max_gpa)

main()

I've got the output as follow:

Enter student name;enter quit to stop: john

Enter major: insy

Enter gpa: 3.5

Enter student name;enter quit to stop: willis

Enter major: mana

Enter gpa: 3.5

Enter student name;enter quit to stop: smith

Enter major: insy

Enter gpa: 3.8

Enter student name;enter quit to stop: quit

Enter major: isny

The highest GPA for isny majors isNone

The problem's output as follow:

function write_students that asks the user for student records and writes them to file students.txt.A record of a student includes name, major and GPA.The user can enter as many records as they want until they type in quit.

function read_students that accepts a major.The function returns the highest GPA for that major.

a program that calls write_students and read_students and prints the major and highest GPA.The programwill ask the user for the major for which to search.Assume all names and majors will be lower case.

Sample input/output might look as follows:

Enter student name; enter quit to stop: jones

Enter major: insy

Enter gpa: 2.0

Enter student name; enter quit to stop: smith

Enter major: insy

Enter gpa: 3.25

Enter student name; enter quit to stop: willis

Enter major: mana

Enter gpa: 3.25

Enter student name; enter quit to stop: quit

Enter major: insy

The highest GPA for insy majors is 3.25

I need help regarding the highest GPA . Thank you in advance

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

\f

Answered: 1 week ago