CS303E Project 1

Instructor: Dr. Bill Young
Due Date: Monday, March 4 at 11:59pm

A Simple Grade Calculator

Many of you wonder about the computation of your grade in this class. At the end of the semester, I create a grading script written in Python that computes your grade from the raw scores downloaded from Canvas, and prints out a grade report. In this assignment, you'll build a very simple version of such a program.

Assignment:

Your task is to create a program to compute several students' semester grades under some simple assumptions. The components of the grade are the following:
  1. there are 3 homeworks, each worth 10 points (collectively worth 30% of the final grade);
  2. there are 2 exams, each worth 100 points (collectively worth 40% of the final grade);
  3. there are 2 projects, each worth 100 points (collectively worth 30% of the final grade).
Your program will ask the user to input each of these 7 grades, validating that each is in the right range. You can assume that the values entered are integers. If the grade entered is not in the proper range, ask for it to be re-entered. (See the examples below.)

After the grades are all entered, you should compute the averages for homeworks, projects, exams and print these out. Also, compute the semester average (using the homework, project and exam averages and the percentage each counts in the final grade) and print that out. All averages should be printed as floating point values with two digits after the decimal point. Finally, print the letter grade for the student, according to the following chart.

Course score Grade
[90...100]A
[80... 90)B
[70... 80)C
[60... 70)D
[ 0... 60)F

Note that, for example, a score of 80 gives a B, not a C.

The program should allow you to process an arbitrary number of students (so you'll need a loop). Exit the program when the user enters 'stop' instead of a student name.

This program is complicated enough that you must use functions to break up the work. For my own version of this program, I defined the following functions:

You don't have to define these exact functions, but you must use functions (a minimum of three) to structure your code. If you can think of a step in the computation as a separable task, write it as a function.

Expected Output:

Below is a sample output for this program. You should match this exactly (for these inputs). Note that this is run from the command line. You can run yours from your IDE, but the TAs should be able to run it from the command line.

> python Project1.py
Enter the student's name (or 'stop'): Susie Woozy

HOMEWORKS:
  Enter HW1 grade: -1
  Grade must be in range [0..10]. Try again.
  Enter HW1 grade: 9
  Enter HW2 grade: 20
  Grade must be in range [0..10]. Try again.
  Enter HW2 grade: 8
  Enter HW3 grade: 9

PROJECTS:
  Enter Pr1 grade: -100
  Grade must be in range [0..100]. Try again.
  Enter Pr1 grade: 200
  Grade must be in range [0..100]. Try again.
  Enter Pr1 grade: 80
  Enter Pr2 grade: 90

EXAMS:
  Enter Ex1 grade: -10
  Grade must be in range [0..100]. Try again.
  Enter Ex1 grade: 75
  Enter Ex2 grade: 85

Grade report for: Susie Woozy
   Homework average (30% of grade): 86.67
   Project average (30% of grade): 85.00
   Exam average (40% of grade): 80.00
   Student course average: 83.50
   Course grade (CS303E: Spring, 2024): B

Enter the student's name (or 'stop'): Bart Simpson

HOMEWORKS:
  Enter HW1 grade: 0
  Enter HW2 grade: 2
  Enter HW3 grade: 4

PROJECTS:
  Enter Pr1 grade: 12
  Enter Pr2 grade: 18

EXAMS:
  Enter Ex1 grade: 22
  Enter Ex2 grade: 11

Grade report for: Bart Simpson
   Homework average (30% of grade): 20.00
   Project average (30% of grade): 15.00
   Exam average (40% of grade): 16.50
   Student course average: 17.10
   Course grade (CS303E: Spring, 2024): F

Enter the student's name (or 'stop'): stop
Thanks for using the grade calculator! Goodbye.

>
Notice that there is no rounding for this project. Use the full numbers in the computations and use format to display the results in the reports. See the Programming Tips below for more discussion on this.

Turning in the Assignment:

The program should be in a file named Project1.py. Submit the file via Canvas before the deadline shown at the top of this page. Submit it to the assignment project1 under the assignments sections by uploading your Python file. Make sure that you following good coding style and use comments.

Your file must compile and run before submission. It must also contain a header with the following format:

# File: Project1.py
# Student: 
# UT EID:
# Course Name: CS303E
# 
# Date: 
# Description of Program: 

Programming Tips

Using literal constants: If you are using the same literal data multiple times, it's a good idea to define it as a constant. For example, this program uses the same error messages repeatedly. Why not define them once at the start of your program so you won't risk mistyping them later:
HW_ERROR_MESSAGE    = "  Grade must be in range [0..10]. Try again."
PR_EX_ERROR_MESSAGE = "  Grade must be in range [0..100]. Try again."
Then, instead of
   print( "  Grade must be in range [0..10]. Try again." )
you'd type
   print( HW_ERROR_MESSAGE )
That way, if you decide later to change the error message, you just have to fix it in one place. By convention, constants have names in all caps. Group constants together at the top of your program.

Format vs. round: When you're asked to print a value to a certain precision you'll typically use the format function. format produces a string suitable for printing. It doesn't change the value stored in memory.

The round function, on the other hand, does create a new value. For example, if you do the following:

num = round(num, 2)
you've actually changed the value of num in memory. It may sometimes be appropriate to use round in computations, but not often.

So, if you're doing computations with the original value, but viewing formatted data, there may be some surprises. For example, suppose a student got a grade of 89.9999. According to our grading scheme, this student would still receive a B because grade < 90. However, if you print the grade to 2 decimal places, it will appear that the student got 90.00, which should merit an A. This is because the printed grade is an approximation of the actual grade.

>>> grade = 89.9999
>>> format( grade, ".2f" )
'90.00'
>>> grade < 90
True
>>> roundedGrade = round( grade, 2 )
>>> roundedGrade
90.0
>>> roundedGrade < 90
False