Calculate Average Score by Reading a File
Explore how to read and process a text file containing class scores in Ruby. Learn to extract data line by line, convert it to integers, and compute the average score rounded to one decimal. This lesson helps develop file handling and basic data manipulation skills using practical examples.
We'll cover the following...
We'll cover the following...
Problem
Write a program that reads the content of a text file that contains scores of a class (0–100, one on each line) and calculates the average score.
Note: The calculated average score is rounded to one decimal point.
File format
The file contains integer values, each appearing on a separate line. Here's a sample file:
84787087
Format of the input file
Expected Output
With the above example, the average calculated would be as follows: ...