Question

Use python

For this program, you will create a grade curving program by reading grades from a file, calculating the mean and standard de

4. The purpose of the calculate Mean) function is to receive the grade list as an argument and using the above mathematical f

Sample Run ---- RESTART: E:/!_CSC119/final_project/ Enter the filename: grades_1H1.txt Number of grades: 20 Mean: 67.15 Stand

Start:


def main():
gradeList = []
  
fileName = getFile()
gradeList = getData(fileName)
mean = calculateMean(gradeList)
sd = calculateSD(mean, gradeList)
displayHeadings(gradeList, mean, sd)
curveGrades(mean, sd, gradeList)
  
  
if __name__ == "__main__":
main()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

===============================================================

Python Script to copy:

# Python script to assign letter grade for given grade

import math # To use sqrt function

# Function to get filename from user

def getFile():

filename = input("Enter the filename: ")

return filename

# Function to read data from input file

def getData(filename):

fin = open(filename, "r") # Open the input file

line = fin.readline() # Read the first line in file

grades = [] # Initializing list to store grades in input file

while line != "":

grades.append(float(line.strip())) # Adding every grade value to list

line = fin.readline() # Read the next line in file

return grades

# Function to calculate Mean for given data

def calculateMean(gradeList):

total = 0

for each in gradeList:

total += float(each)

mean = total / len(gradeList)

return mean;

# Function to calculate standard deviation for given data

def calculateSD(mean, gradeList):

total = 0

for i in gradeList:

total += (float(i) - mean)**2 # ** indicates value to the power i.e, x*x

stdev = total / (len(gradeList)-1)

return math.sqrt(stdev);

# Function to display titles or headings of output data

def displayHeadings(gradeList, mean, sd):

print("Number of grades: ",len(gradeList))

print("Mean: ",mean)

print("Standard Deviation: ",'{:.4f}'.format(sd))

print("\n\t",'{:7s}'.format("Score Grade"))

# Function to assign letter grade for respective grade

def curveGrades(mean, sd, gradeList):

slno = 1 # Variable to represent serial number

for grade in gradeList:

# Calculate the letter grade

if grade >= (mean + 1.5*sd):

letterGrade = 'A'

elif grade >= (mean + 0.5*sd) and grade < (mean + 1.5*sd):

letterGrade = 'B'

elif grade >= (mean - 0.5*sd) and grade < (mean + 0.5*sd):

letterGrade = 'C'

elif grade >= (mean - 1.5*sd) and grade < (mean - 0.5*sd):

letterGrade = 'D'

elif grade < (mean - 1.5*sd):

letterGrade = 'F'

print('{:2d}'.format(slno),'{:7.2f}'.format(grade),letterGrade.rjust(3," "))

slno += 1 # Incrementing serial number

# Main function to test all functions above

def main():

gradeList = []

fileName = getFile()

gradeList = getData(fileName)

mean = calculateMean(gradeList)

sd = calculateSD(mean, gradeList)

displayHeadings(gradeList, mean, sd)

curveGrades(mean, sd, gradeList)

if __name__ == "__main__":

main()

---------------------------------------------------

Python script screenshots:

1 2 # Python script to assign letter grade for given grade import math # To use sqrt function 3 4 5 # Function to get filenam

27 28 29 30 # Function to calculate standard deviation for given data def calculateSD (mean, gradeList): total = 0 for i in g

print({:2d}.format(slno), {:7.2f}.format(grade), letterGrade.rjust(3, )) slno += 1 # Incrementing serial number 58 59 6

------------------------------------------------------------------

Sample Input:

File name: input.txt

input.txt 1 2 3 4 5 6 7 8 9 10 11 12 13 59 60 65 75 56 80 66 62 88 72 85 71 63 77 65 77 65 50 45 62 14 15 16 17 18 19 20 21

-------------------------------------------------------

Sample Output:

Enter the filename: input.txt Number of grades: grades: 20 Mean: 67.15 Standard Deviation: 11.0610 1 2 3 4 5 6 7 9 10 11 12 1

===================================================================

Hope it will helpfull and do comments for any additional info if needed. Thankyou

===================================================================

Add a comment
Know the answer?
Add Answer to:
Use python Start: def main(): gradeList = []    fileName = getFile() gradeList = getData(fileName) mean...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python Program Preview File Edit View Go Tools Window OO 95% Help An Intro...

    Write a Python Program Preview File Edit View Go Tools Window OO 95% Help An Intro to Programming Using Python (2) (1) (1).pdf (page 256 of 431) Mon 11:28 AM Q E © Q Search 2. Curve Grades Statisticians use the concepts of mean and standard deviation to describe a collection of numbers. The mean is the average value of the numbers, and the standard deviation measures the spread or dispersal of the numbers about the mean. Formally, if X1,...

  • C++ Use C++ functions and build a program that does the most basic job all students...

    C++ Use C++ functions and build a program that does the most basic job all students have to contend with, process the grades on a test and produce a summary of the results. The big wrinkle is, it should be a multi-file program. -Requires three simple things: Figure out the best score of all scores produced Figure out the worst score of all scores produced Assign a letter grade for each score produced Complete this lab by writing three functions....

  • I really need help with this python programming assignment Program Requirements For part 2, i need...

    I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n):   lst = []   for i in range(1,n+1):     val = float(input('Enter float '+str(i)+': '))     lst.append(val)   return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • Hi. Could you help me write the below program? Please don't use any header other than...

    Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you! For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of...

  • // READ BEFORE YOU START: // You are given a partially completed program that creates a...

    // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...

  • Write your final answers on the lines. Show your computations. Use correct symbols. 1. For the...

    Write your final answers on the lines. Show your computations. Use correct symbols. 1. For the following variables determine the level of measurement and whether the variable is discrete or continuous The time it takes a rat to run a maze Rank in the Army Number of students enrolled in PSY 202 Race (as in Asian, etc.) 2. How would the following mathematical operation be expressed in summation notation? "Add two to each score, square the resulting values, then add...

  • Researchers randomly assigned 322 moderately obese volunteers to one of three diets to study how ...

    Researchers randomly assigned 322 moderately obese volunteers to one of three diets to study how the diets compare with respect to various outcomes such as weight loss, lipid profiles, blood pressure, and other indicators of health and metabolic function. The three diets included a low-carbohydrate diet, a low-fat diet, and a Mediterranean diet that consists of moderate fat and a high proportion of monounsaturated fats. All study participants worked at the same research center in Israel, where lunch (the main...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT