Lab 2 – Student Grade Program

Python Learning Lab Assignment: Loops, If Statements, and Functions

Project Link

Objective:
This assignment is designed to help you practice using loops (while), if statements, and functions to build a modular and efficient Python program. By completing this assignment, you will learn to:

  • Define and use functions to organize and reuse code.
  • Implement loops and conditional statements within functions.
  • Develop a structured program that performs multiple related tasks.

Program Overview:
You will create a modular grade management system that allows users to:

  • Input grades for multiple students.
  • Calculate the average grade.
  • Determine the highest and lowest grades.
  • Report the number of students in each grade category (A, B, C, D, F).
  • Repeat the process as needed.

Part 1: Defining Functions

Task 1: Create a Function to Collect Grades
Objective: Define a function that collects grades for a specified number of students, ensuring that each grade entered is valid (between 0 and 100).

  • Function Name: get_grade
  • Behavior:
    Use a loop to prompt the user to enter a grade. Implement input validation to ensure that each grade is between 0 and 100. If an invalid grade is entered, prompt the user to re-enter the grade.
  • Returns:
    A valid grade entered by the user.

Part 2: Processing Grades

Task 2: Count the Number of Students in Each Grade Category
Objective: Instead of categorizing each grade, count the number of students in the A, B, C, D, and F grade categories.

  • Function Name: report_grade_counts
  • Parameters:
    • a_count, b_count, c_count, d_count, f_count: Integers representing the number of students in each grade category.
  • Behavior:
    Prints the number of students in each category.

Task 3: Calculate the Average Grade
Objective: Define a function that calculates the average of all grades entered.

  • Function Name: calculate_average
  • Parameters:
    • total_sum (float): The total sum of all student grades.
    • num_students (int): The number of students.
  • Returns:
    The average grade as a float.

Part 3: Main Program

Task 4: Create the Main Program
Steps to implement in the main function:

  1. Prompt for Grades:
    Continuously prompt the user for grades until they input -1 to stop.
  2. Calculate Grade Statistics:
    • Use loops and if statements to count the number of students in each grade category (A, B, C, D, F).
    • Calculate the total sum of grades.
  3. Calculate Average, Highest, and Lowest Grades:
    • After the user finishes entering grades, calculate the average, highest, and lowest grades.
  4. Display Results:
    • Print the number of students in each grade category.
    • Print the average, highest, and lowest grades.
  5. Repeat Option:
    • Ask the user if they want to enter another set of grades.

Part 4: Test Cases

You will need to test the program with the following input sets to verify correctness:

Test Input Set 1: Basic Functionality

Enter a grade (0-100) or -1 to finish: 85
Enter a grade (0-100) or -1 to finish: 92
Enter a grade (0-100) or -1 to finish: 78
Enter a grade (0-100) or -1 to finish: -1

Expected Outputs:

Average Grade: 85.00
Highest Grade: 92
Lowest Grade: 78
A's: 1
B's: 1
C's: 1
D's: 0
F's: 0

Test Input Set 2: Edge Cases with Boundary Values
Test grades on the boundaries between categories.

Test Input Set 3: Invalid Grade Inputs
Test entering invalid grades and re-entering valid ones.

These tests will help you verify that the program handles basic functionality, boundary cases, and invalid inputs correctly.


Submission:

Submit your completed Python file with all the tasks implemented. Ensure that your program is modular, functions are properly defined and called, and the program produces the expected outputs. Comment your code appropriately to explain the purpose of each function and significant blocks of code.

Grading

RequirementsGrading CommentsPointsScore
Completion of all functional requirements50
Code broken up in to functions10
Appropriate code formatting5
Meaningful identifier names (variables, functions)10
Comments at the top (name, date), and on all functions5
All tests run, output correct, and results in testruns.txt20
Total100

Edit

Happy coding!

Scroll to Top