Ask Question
11 August, 18:47

Write a program that reads a file consisting of students' test scores in the range 0-200. It should then determine the number of students having scores in each of the following ranges:

0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200.

Output the score ranges and the number of students. (Run your program with the following input dа ta:

76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189.)

+5
Answers (1)
  1. 11 August, 19:29
    0
    The solution code is written in Python:

    with open ("text1. txt") as file: data = file. read () numbers = data. split (",") group_0_24 = 0 group_25_49 = 0 group_50_74 = 0 group_75_99 = 0 group_100_124 = 0 group_125_149 = 0 group_150_174 = 0 group_175_200 = 0 for x in numbers: if int (x) > 174: group_175_200 = group_175_200 + 1 elif int (x) > 149: group_150_174 = group_150_174 + 1 elif int (x) > 124: group_125_149 = group_125_149 + 1 elif int (x) > 99: group_100_124 = group_100_124 + 1 elif int (x) > 74: group_75_99 = group_75_99 + 1 elif int (x) > 49: group_50_74 = group_50_74 + 1 elif int (x) > 24: group_25_49 = group_25_49 + 1 else: group_0_24 = group_0_24 + 1 print ("Group 0 - 24: " + str (group_0_24)) print ("Group 25 - 49: " + str (group_25_49)) print ("Group 50 - 74: " + str (group_50_74)) print ("Group 75 - 99: " + str (group_75_99)) print ("Group 100 - 124: " + str (group_100_124)) print ("Group 125 - 149: " + str (group_125_149)) print ("Group 150 - 174: " + str (group_150_174)) print ("Group 175 - 200: " + str (group_175_200))

    Explanation:

    Firstly, open and read a text file that contains the input number (Line 1 - 2).

    Since each number in the text file is separated by a comma "," we can use split () method and put in "," as a separator to convert the input number string into a list of individual numbers (Line 3).

    Create counter variables for each number range (Line 5 - 12).

    Next create a for-loop to traverse through the number list and use if-else-if block to check the range of the current number and increment the relevant counter variable by 1 (Line 14 - 37).

    Display the count for each number range using print () function (Line 39 - 46)
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that reads a file consisting of students' test scores in the range 0-200. It should then determine the number of students ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers