Respuesta :
Answer:
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)