Grade Calculator Programming – Day 1

Today, we started development of the minimum grade calculator in Computer Science 1.

#Programmer Name: Eric Evans, M.Ed.
#Program Name: Grade Calculator
#Program Description: Provides a minimum grade needed to get a C, B, or A in a given course for the semester and for the year.
#
print ("*********************************************************")
print ("** Welcome to the Grade Calculator                     **")
print ("**                                                     **")
print ("** You will need the following information to proceed: **")
print ("** - Fall Semester (S1) Grade                          **")
print ("** - 3rd Quarter (Q3) Grade                            **")
print ("**                                                     **")
print ("*********************************************************")
print ("")

Here, we started with our generic header and then a welcome screen that lets the user know what to expect and what they will need to proceed.

minC = 68.5
#Minimum average grade for "C" per Ferris ISD
minB = 79.5
#Minimum average grade for "B" per Ferris ISD 
minA = 89.5
#Minimum average grade for "A" per Ferris ISD

Here, are establishing the minimum graded needed to pass (minC), and get a B (minB) and an A (minA) according to our current grading guidelines.

s1 = float(input("What is your Fall Semester (S1) Grade? "))
#Ask for S1 input and cast as float
q3 = float(input("What is your 3rd Quarter (Q3) Grade? "))
#Ask for Q3 input and cast as float

Here, we are creating a variable named s1, which is going to hold the data entered by the user for their fall semester grade. We then create a variable named q3which is going to hold the data entered by the user for their 3rd quarter grade.

semMinC = ( ( ( 5 * minC ) - ( q3 * 2 ) ) / 3 )
#C Algorithm - Developed on 19-March-2018
semMinB = ( ( ( 5 * minB ) - ( q3 * 2 ) ) / 3 )
#B Algorithm - Developed on 19-March-2018
semMinA = ( ( ( 5 * minA ) - ( q3 * 2 ) ) / 3 )
#A Algorithm - Developed on 19-March-2018

Here is where we get to use the algorithm that was developed in the previous class ( Grade Calculator Algorithm Development ).

You will notice that it is being used 3 different times. Each case is separate to address the 3 different grade breaks (68.5, 79.5, and 89.5).

semMinCRounded = round(semMinC,2)
#Rounds minimum "C" output to 2 decimal points
semMinBRounded = round(semMinB,2)
#Rounds minimum "B" output to 2 decimal points
semMinARounded = round(semMinA,2)
#Rounds minimum "A" output to 2 decimal points

Here, we take the solution for each case and then round it to 2 decimal points.

semMinCString = str(semMinCRounded)
#Casts minimum "C" output as string
semMinBString = str(semMinBRounded)
#Casts minimum "B" output as string
semMinAString = str(semMinARounded)
#Casts minimum "A" output as string

Here, we are casting the rounded output as a string so we can use it in our output.

print("")
print("***********Q4 & SE2 MINIMUMS (SEMESTER)***********")
print("Min for C for Semester = " + semMinCString)
#Outputs minimum for "C" for semester
print("Min for B for Semester = " + semMinBString)
#Outputs minimum for "B" for semester
print("Min for A for Semester = " + semMinAString)
#Outputs minimum for "A" for semester

Here we finally provide our output for the use to see.

This code is deliberately broken-up so the students can see and manipulate the various components. (e.g., lines 24, 30, and 36).

Here is a consolidated version of the code that combines multiple steps:

#Programmer Name: Eric Evans, M.Ed.
#Program Name: Grade Calculator
#Program Description: Provides a minimum Grade
#
print ("*********************************************************")
print ("** Welcome to the Grade Calculator                     **")
print ("**                                                     **")
print ("** You will need the following information to proceed: **")
print ("** - Fall Semester (S1) Grade                          **")
print ("** - 3rd Quarter (Q3) Grade                            **")
print ("**                                                     **")
print ("*********************************************************")
print("")
minC = 68.5
#Minimum average grade for "C" per Ferris ISD
minB = 79.5
#Minimum average grade for "B" per Ferris ISD 
minA = 89.5
#Minimum average grade for "A" per Ferris ISD
s1 = float(input("What is your Fall Semester (S1) Grade? "))
#Ask for S1 input and cast as float
q3 = float(input("What is your 3rd Quarter (Q3) Grade? "))
#Ask for Q3 input and cast as float
semMinC = str ( round ( ( ( ( 5 * minC ) - ( q3 * 2 ) ) / 3 ), 2) )
#C Algorithm - Developed on 19-March-2018 rounded to 2 decimal places and cast as a string
semMinB = str ( round ( ( ( ( 5 * minB ) - ( q3 * 2 ) ) / 3 ), 2) )
#B Algorithm - Developed on 19-March-2018 rounded to 2 decimal places and cast as a string
semMinA = str ( round ( ( ( ( 5 * minA ) - ( q3 * 2 ) ) / 3 ), 2) )
#A Algorithm - Developed on 19-March-2018 rounded to 2 decimal places and cast as a string
print("")
print("***********Q4 & SE2 MINIMUMS (SEMESTER)***********")
print("Min for C for Semester = " + semMinC)
#Outputs minimum for "C" for semester
print("Min for B for Semester = " + semMinB)
#Outputs minimum for "B" for semester
print("Min for A for Semester = " + semMinA)
#Outputs minimum for "A" for semester

You can see that lines 24 through 29 are compressed versions of lines 24 through 41 of the original code. Let’s take a quick look at how this was accomplished:

semMinC = str ( round ( ( ( ( 5 * minC ) - ( q3 * 2 ) ) / 3 ), 2) )

Here is line 24 of the compressed version. You can see that we have a math problem in the middle that is rounded to 2 decimal points that is cast as a string.

The original (expanded) code took the following lines to accomplish the same thing:

semMinC = ( ( ( 5 * minC ) - ( q3 * 2 ) ) / 3 )
semMinCRounded = round(semMinC,2)
semMinCString = str(semMinCRounded)

When we return next class, the students will be developing the second part of the program, which addresses the minimums needed for the 3 cases for the year.

For reference, here is a link to the IDE of the code at this checkpoint:

Grade Calculator Algorithm Development

My Computer Science 1 classes have spent the past two class periods developing two different algorithms for a “minimum grade calculator” assignment.

Our grades are broken up as follows:

  • Semester 1 (S1) – 50% of Year
    • Quarter 1 (Q1) – 45% of Semester 1
    • Quarter 2 (Q2) – 45% of Semester 1
    • Semester Exam 1 (SE1) – 10% of Semester 1
  • Semester 2 (S2) – 50% of Year
    • Quarter 3 (Q3) – 45% of Semester 2
    • Quarter 4 (Q4) – 45% of Semester 2
    • Semester Exam 2 (SE2) – 10% of Semester 2

The assignment was to develop a program that would let students know the minimum needed grade(s) for the remaining grading periods to pass for both the semester and for the year. As part of this project, the only remaining grades are Q4 and SE2. This is 55% of the semester and 27.5% of the year.

We started by spending two days in algorithm development. The play had been for one day, but you’ll see why it took us two days.

Algorithm – Minimum for Semester

We started with development of a minimum grade for the semester. So, we started with this:

s2 = ( ( q3 * 2 ) + ( q4 * 2 ) + se2 ) / 5

We then condensed it to the following:

s2 = ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5

The “MIN” is the minimum grade that is needed for the 3/5 of the average that is still outstanding. We then moved to isolate the “MIN” variable as follows:

s2 = ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5
( 5 * s2 ) = ( q3 * 2 ) + ( MIN * 3 )
( 5 * s2 ) - ( q3 * 2 ) = MIN * 3
( ( 5 * s2 ) - ( q3 * 2 ) ) / 3 = MIN

We verified the algorithm against an established dataset and it checked.

Algorithm – Minimum for Year (Take 1)

The minimum for the year algorithm was the one that gave us a problem. We got it developed by the end of the first day, but it failed testing. You’ll see why, but we didn’t get a chance to correct it until the next class.

We started with the following:

y = ( s1 + s2 ) / 2

We then expanded it to the following:

y = ( s1 + ( ( ( q3 * 2 ) + ( q4 * 2 ) + se2 ) / 5 ) ) / 2

Like earlier, we consolidated the 6/10 of the year average (3/5 of the semester 2 average) as follows:

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2

The “MIN” is the minimum grade that is needed for the 3/5 of the semester average that is still outstanding. We then moved to isolate the “MIN” variable as follows: (NOTE: This is where our error occurred).

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2
2 * y = s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 )
( 10 * y ) = s1 + ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  = ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  - ( q3 * 2 ) = ( MIN * 3 ) 
( ( 10 * y ) - s1  - ( q3 * 2 ) ) / 3 = MIN

When we verified this against the dataset, it failed the tests. Regretfully, we ran out of time to correct it, so we had to push the correction to the next class period.

Algorithm – Minimum for Year (Take 2)

We verified the original algorithm once again and determined that it was wrong and would result in a logic error if used.

We analyzed the notes:

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2
( 2 * y ) = s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 )
( 10 * y ) = s1 + ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  = ( q3 * 2 ) + ( MIN * 3 )
( 10 * y ) - s1  - ( q3 * 2 ) = ( MIN * 3 ) 
( ( 10 * y ) - s1  - ( q3 * 2 ) ) / 3 = MIN

We discovered that the error occurred at line 3. So, we adjusted the algorithm as follows:

y = ( s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 ) ) / 2
( 2 * y ) = s1 + ( ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5 )
( ( 2 * y ) - s1 ) = ( ( q3 * 2 ) + ( MIN * 3 ) ) / 5
( 5 * ( ( 2 * y ) - s1 ) ) = ( q3 * 2 ) + ( MIN * 3 )
( ( 5 * ( ( 2 * y ) - s1 ) ) - ( q3 * 2 ) ) = MIN * 3
( ( 5 * ( ( 2 * y ) - s1 ) ) - ( q3 * 2 ) ) / 3 = MIN

We verified the algorithm against an established dataset and it checked.