Here's a common data science exercise: working with student names and class grades. A file called grades.csv contains 500 lines. Each line is in this format: last,first,grade. All grades are between 0 and 100. (All names and grades are fake.)
Here are some challenges for you:
Print each last,first name and a letter grade, given that: < 60 is an F, 60-69 is a D, 70-79 is a C, 80-89 is a B, and 90 or above is an A.
How many As, Bs, Cs, Ds, and Fs did the class end up with (Ans: 84, 203, 154,41, 8.)
What was the average grade? (Ans: 73).
What is the class GPA if A=4.0, B=3.0, C=2.0, D=1.0, F=0? (Ans: 1.70)
For the "Dean's List," print just students who got an "A."
For the "academic probation list," print just students who got a "D" or "F."
Who got the highest grade? Or were there more than one with the highest?
Now you try. Run some data science on these grades.
Type your code here:
See your results here:
This code will just print the names and grades to the screen.
Might be helpful:
Since all fields of the lines in this file are not numbers (they're a mix of numbers and strings), do not use explode to break them apart. Use explode_str to break them into an array of strings.
If you need to convert a string to a number, use the tonumber() function.
strings = explode_str("separator","string") -- explodes string into an array of strings.
If arr is an array, then #arr will tell you how many elements are in the array.
Arrays in Lua always start at 1 (not 0).
Share your code
Show a friend, family member, or teacher what you've done!