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 |
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:
> 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.
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:
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