Problem Description



Files, ListsSkills required: read a file, manipulate a list, split a stringProgram name: homework_average.pyProblem DescriptionWe will write a program that will compute homework averages for an unknown number of students.InputWrite a program to read a file where each line is in the following format:name n1 n2 n3…"name" is the first name of a student and the following "nx" values are homework scores. All values are separated by one or more spaces.You do not know the name of the input file. Prompt the user for the file name, but make the default file name: "studentdata.txt" so if the user just presses the Enter key, that is the file that will be used.You do not know how many lines are in the file.You do not know how many homework scores each student has, but each student has at least two.Processing and outputRead the file into a list of lines (strings). Then do the following for each line: Read the line. Split the data on the line into individual values. The first value will be the name; all remaining values will be scores. Since all input is string data, you will need to convert each score in the list into an pute the average for each student. Note that the number of scores varies.Print the student name, followed by the average (a floating point number displayed with one decimal place) followed by the scores. Each name should be left-aligned in a 10-column field. The average should be displayed right-aligned in a 6-column field with one decimal place. The remaining scores can be printed on a separate line in list form. Optional challenges:Send the numeric data to a function that will compute and return (not print) the average homework score of all scores except the lowest score. For example, if the scores are 70, 80, and 90, you would add up all 3 scores (240), subtract the lowest (70) giving 170, and divide that number by one less than the number of scores (3-1=2). 170/2 = 85. The function should return the 85.0. Note that you must return a float, not an int.Put all of the output data on a single line, and print the numbers without the quotation marks (convert the strings to ints).Sample session:Tom Kleen, Homework AverageFile name? studentdata.txtjoe 81.0[100, 75, 80, 90, 60]bill 90.0[90, 90, 90, 90, 90]sue 86.4[90, 80, 85, 95, 90, 80, 85]grace 76.7[70, 80, 85, 80, 95, 50]john 68.3[0, 70, 80, 85, 80, 95] ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download