
Your program should use a loop to read data from a text file which contains students' names and 3 exam scores. The program should calculate the exam average for each student, determine the appropriate letter grade for that exam average, and print the name, average, and letter grade. After printing all this, you need to print the count of the total number of A's, B's, C's, D's, and F's for the whole class.
The text file you need to use can be accessed using this link: scores.txt.
Copy this file to the folder where your program will reside. The text file contains a list of 30 records, and each record contains a name and that person's 3 test scores. Each field is separated by a tab character. The first 2 records looks like this:
Davis 88 92 84
Wilson 98 80 73
and so on. Your program will need to open this file and read each line until the end of file. I recommend calculating a student's exam average and letter grade as you read the file, although this is not a strict requirement.
Once you've calculated the exam average from the 3 scores for a student, like student Davis or Wilson above, you can find their letter grade using the following grading scale.
90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
< 60 F
So, your output should look something like the following, but with all 30 students and an accurate count for the number of A's, B's, C's, D's, and F's. There may or may not be 4 A's and 8 B's.
To get full credit your program needs to accomplish the following.
- You need to print each student's name, exam average, and letter grade based on the averages of their 3 exam scores.
- After printing all 30 of the names, averages, and grades, you need to print a summary stating the number of the number of A's, B's, C's, D's, and F's for the whole class.
- To get the letter grades you'll need to calculate the average of the 3 exam for each student and determine the appropriate letter grade for that average based on the criteria listed above. The code that determines the letter grade needs to be in it's own function.
- You need to process the data with a loop, and that loop should be able to work properly even if the number of students in the file varies from day to day. That is, don't use 30 as a magic number. The program should work no matter how many records the file might contain.
- Your program must have at least 2 functions written by you. A main() function, and a function to determine the letter grade. You could easily have more than 2 functions if you choose, but you need 2 minimum. The non-main function should require passing an argument (or augments) or returning a value, or both. Knowing how to do arguments/return values is a goal of the exercise.
- Also, it is time we used a little formatting. Use formatting to have the names and grades all line up in neat columns. That is, the letter grades should print in their own straight column, where the grade's printed position does not vary with the length of the name.
- My source codedef main():
def main(): - #set count of grades
readFile()
#readFile reads text file scores.txt and print the name,grade and count of each grade
def readFile():
name=""
gradeA=0
gradeB=0
gradeC=0
gradeD=0
gradeF=0
avg=0
print('Name','Average','Grade')
print("-"*30)
studFile=open('scores.txt','r')
for line in studFile.readlines():
val=line.split()
avg=(float(val[1])+float(val[2])+float(val[3]))/3.0
grade=getGrade(avg)
#count grades of each letter
if(grade=='A'):
gradeA=gradeA+1
elif(grade=='B'):
gradeB=gradeB+1
elif(grade=='C'):
gradeC=gradeC+1
elif(grade=='D'):
gradeD=gradeD+1
elif(grade=='F'):
gradeF=gradeF+1
print(val[0], avg, grade)
#print grades
print('Number of A''s:', gradeA)
print('Number of B''s:', gradeB)
print('Number of C''s:', gradeC)
print('Number of D''s:', gradeD)
print('Number of F''s:', gradeF)
#Returns character grade
def getGrade(avg):
grade=' '
#Set grade on average score
if(avg>=90):
grade='A'
elif avg>=80 and avg<90:
grade='B'
elif avg>=70 and avg<80:
grade='C'
elif avg>=60 and avg<70:
grade='D'
else:
grade='F'
return grade
main()

Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 7 images

- Exercise Write the pseudo code and flowchart that will read a file of student test results and produce a student test grade report. Each test record contains the student number, name and test score (out of 50). The program is to calculate for each student the test score as a percentage and to print the student's number, test score (out of 50) and letter grade on the report. The letter grade is determined as follows: A = 90-100% B = 80-89% C = 70-79% 90-100 80-89 :A :B D = 60-69% E = 0 -59%arrow_forwardWhat does the following python code do? f = open("sample.txt", "w") Choose all that apply. Select 2 correct answer(s) Question 14 options: If the file called sample.txt exists, it writes at the bottom of the file writes "w" to the file called sample.txt closes a file called sample.txt opens a file called sample.txt for appending opens a file called sample.txt for reading reads the file called sample.txt starting from the top if the file sample.txt exists, deletes everything in it if the file sample.txt does not exist, it creates the file and opens it for writingarrow_forwardThis list attached below is a chronological list of the World Series winning teams from 1903 through 2009. (The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2009. Note the World Series was not played in 1904 or 1994.) Write a python program that lets the user enter the name of a team, then displays the number of times that team has won the World Series in the time period from 1903 through 2009. Boston Americans New York Giants Chicago White Sox Chicago Cubs Chicago Cubs Pittsburgh Pirates Philadelphia Athletics Philadelphia Athletics Boston Red Sox Philadelphia Athletics Boston Braves Boston Red Sox Boston Red Sox Chicago White Sox Boston Red Sox Cincinnati Reds Cleveland Indians New York Giants New York Giants New York Yankees Washington Senators Pittsburgh Pirates St. Louis Cardinals New York Yankees New York Yankees Philadelphia Athletics Philadelphia Athletics St. Louis Cardinals New York Yankees New York…arrow_forward
- PYTHON!!! The credit plan at TidBit Computer Store specifies a 10% down payment and an annual interest rate of 12%. Monthly payments are 5% of the listed purchase price, minus the down payment. Write a program that takes the purchase price as input. The program should display a table, with appropriate headers, of a payment schedule for the lifetime of the loan. Each row of the table should contain the following items: The month number (beginning with 1) The current total balance owed The interest owed for that month The amount of principal owed for that month The payment for that month The balance remaining after payment The amount of interest for a month is equal to balance × rate / 12. The amount of principal for a month is equal to the monthly payment minus the interest owed. An example of the program input and output is shown below: Enter the puchase price: 200 (SEE IMAGE FOR PURCHASE PRICE CHART) Results you should get: Input: 200 Output: Purchase price: 200…arrow_forward The fields below repeat for each customer: o Customer name (String)o Customer ID (numeric integer) o Bill balance (numeric)o EmailAddress (String)o Tax liability (numeric or String) The customers served by the office supply store are of two types: tax-exempt or non-tax- exempt. For a tax-exempt customer, the tax liability field on the file is the reason for the tax exemptions: education, non-profit, government, other (String). For a non-tax exempt customer, the tax liability field is the percent of tax that the customer will pay (numeric) based on the state where the customer’s business resides. Program requirements: From the information provided, write a solution that includes the following: A suitable inheritance hierarchy which represents the customers serviced by the office supply company. It is up to you how to design the inheritance hierarchy. I suggest a Customer class and appropriate subclasses.. For all classes include the following: o Instance variables o…arrow_forwardCreate a function using a "while" loop. The function asks the user to input a number between 10 and 20. If the number is not within the specified limits, the user must change his/her input until he/she enters the correct value.arrow_forward
- Again, modify the while loop to utilize tolower() or toupper(). Create two more functions (options #3 and #4 in your menu) by taking the to_kilograms() and to_pounds() functions and modifying them to use reference variables instead of normal pass by value variables. Name them: to_kilograms_ref() to_pounds_ref() Create another two functions (options #5 and #6 in your menu) by taking the to_kilograms() and to_pounds() functions and modifying them to use pointers instead of normal pass by value variables. Name them: to_kilograms_ptr() to_pounds_ptr() Your new Menu should look like this, which includes what type of variables are being used: MENU 1. Kilograms to Pounds (pass by value) 2. Pounds to Kilograms (pass by value) 3. Kilograms to Pounds (pass by reference) 4. Pounds to Kilograms (pass by reference) 5. Kilograms to Pounds (using pointers) 6. Pounds to Kilograms (using pointers) Example: #include <iostream> #include <cmath>…arrow_forwardEXCEL VBA (a) Write a user-defined function called SumStop which takes an integer n as an input and adds up the values of the cells in row 1 (starting from cell A1) until the value of the sum exceeds n, and then outputs the number of cells used. You may assume that all of the cells in row 1 contain numbers. Use a suitable Do While loop and the cells command. Declare all variable types and include appropriate comments in your code.arrow_forwardprofile-image Time remaining: 00 : 09 : 42 Computer Science C++. Need help writing a program that plays the game of Hangman. The program should pick a word (which is either coded directly into the program or read from a text file) and display the following: Guess the word: XXXXXX Each X represents a letter. The user tries to guess the letters in the word. The appropriate response yes or no should be displayed after each guess. After each incorrect guess, display the diagram with another body part filled. After seven incorrect guesses, the user should be hanged. The display should look as follows: O /|\ | / \ After each guess, display all user guesses. If the user guesses the word correctly, display: " Congratulations!!! You guessed my word. Play again? yes/no " Please help in making this code and if possible to include steps to learn what most of the lines and functions do in order to understand it better. Thank you.arrow_forward
- Turn the following code into a procedure. Pass the input file and the amount of PM 10 to the procedure. It will print the city name and the pollution values for all cities that have that much PM 10 pollution or more.arrow_forwardThis program asks the user to enter 4 names for a team, storing them in an array of Strings. Then the program asks for one of those names again, and a new name to substitute instead of that one. Finally, the program changes the array, making that substitution. This modified list of names is printed on the screen. You can see sample output at the end of this file.arrow_forward9.Code please. In this exercise you will create a program that will be used in a digital library to format and sort journal entries based on the authors last name. Each entry has room to store only the last name of the author. Begin by removing the first name "Isaac" from the string variable journal_entry_1 by using the string function erase. Do not forget to also remove the whitespace so that the string variable journal_entry_1 will then contain the string "Newton" with no whitespaces. The journal entries should be sorted alphabetically based on the authors last name. For example, the last name "Brown" should come before the last name "Davis" Create an if statement so that if the last name contained within journal_entry_2 is alphabetically less than the last name contained within journal_entry_1, then the string values are swapped using the string function swap. You may use either of the comparison operators < > in the if statement but remember that following ASCII, "A" is…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





