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: