Question

write a python program that reads from a file, scores.txt, a list of test scores. the...

write a python program that reads from a file, scores.txt, a list of test scores. the program should calculate the average of all the scores, and print to the screen. the program should also have a function, num_passing, that takes as a parameter the list or grades and returns the number of scores that are above 64.

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

CODE:


def find_average(filename): //function to find the average of numbers
my_file = open(filename, 'r') //open file in read mode
scores = [float(line) for line in my_file.readlines()] //loading all lines in to a list named scores
my_file.close() //close the open file
mean = sum(scores)/len(scores) //calculate the mean of all scores
print(mean) //print mean
return scores //return scores
  
  
def num_passing(numbers): //function for counting numbers greater than 64
count = len([i for i in numbers if i > 64]) //counts the numbers that are greater than 64
return(count) //return count
  
  
  
def main():   
numbers=find_average('scores.txt') //call find_average function and store the list in numbers
print(num_passing(numbers)) //print count
  

main()

OUTPUT:

First line(55.0) is the average value

second line(4) is the count

sample text file i took

save file as scores.txt and put this in same folder in which code is saved

if u understand this upvote else drop a comment

ss.

scores - Notepad Edit Format View File Help

Add a comment
Know the answer?
Add Answer to:
write a python program that reads from a file, scores.txt, a list of test scores. the...
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 complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • In python programming Write a program that opens the EmployeeSalaries.txt file and reads the salaries into...

    In python programming Write a program that opens the EmployeeSalaries.txt file and reads the salaries into a list. The program should output: The lowest salary in the list The highest salary in the list The total of all salaries in the list The average of all salaries in the list

  • Write a program that reads the scores from the file and displays their total and average.

    Suppose that a text file Lab2.txt contains an unspecified number of scores. Write a program that reads the scores from the file and displays their total and average.In the text file, the scores are separated by blanks.The program should contain two methods with these signatures (it can contain other methods besides these if you think appropriate):public static double totalScores(File inFile)public static double averageScores(File inFile)The output from the program should look like this successful sample run from my solution:The total of...

  • Python Program 5. Write a Python program in a file named validTime.py. Include a function named...

    Python Program 5. Write a Python program in a file named validTime.py. Include a function named string parameter of the form hh:mm: ss in which these are numeric validTime that takes a values and returns True or False indicating whether or not the time is valid. The number of hours, minutes, and seconds must two digits and use a between 0 and 9). The number of hours must be between 0 and 23, the number of minutes and seconds must...

  • c++ reading file that contains names and scores to compute averages, return scores when names are inputed and return if a students scores is aobve equal to or below the average

    Given a score file named as scores.txt, the named file is posted alone side with the assignment. The score file has two part: first line is number of students and the rest is a list of names with scores. For example: 3 Tommy 35.5 John 77.2 David 59.4 The first function should be named as getScore and it takes a string parameter as input that is a student’s name, you then open the given score file, read the contents and return the student’s score stored in...

  • Write a program in C++ to: 1. Read all records from a binary file (also attached...

    Write a program in C++ to: 1. Read all records from a binary file (also attached to this email) to arrays; (the record structure: student number (20 bytes), grade (integer)) 2. Sort the list according to test scores; 3. Calculate the average test score for the class and print on the screen; 4. write sorted records to a new binary file. For example: The records in the original file: 1 89 2 95 3 76 The new file sorted by...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

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
ADVERTISEMENT