Lab 2 – Student Grade Program (Sp 25)

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

Project Start Link

Objective

In this lab you will practice while loops, if statements, and functions by writing a modular program that works with student grades. By the end of this lab, you should be able to:

  • Write and call functions to organize code.
  • Use loops and conditionals to control program flow.
  • Create a structured program that repeats tasks until the user decides to quit.

Program Overview

You will create a grade management program that allows a user to:

  1. Enter grades for multiple students (stop by typing -1).
  2. Keep a running total of the grades as they are entered.
  3. Calculate the average grade.
  4. Find the highest and lowest grades.
  5. Count how many students earned A, B, C, D, or F.
  6. Repeat the whole process as many times as the user wants.

Part 1: Functions

Task 1: Collecting a Single Grade

Function Name: get_grade

  • Use a loop to prompt for a grade.
  • Only accept numbers between 0 and 100.
  • If the user enters something invalid, ask again until it is valid.
  • Return the valid grade.

Part 2: Processing Grades

Task 2: Report Counts by Grade Category

Function Name: report_grade_counts
Parameters: a_count, b_count, c_count, d_count, f_count

  • Print the number of students in each category.
  • Use this grading scale:
    • A = 90–100
    • B = 80–89
    • C = 70–79
    • D = 60–69
    • F = below 60

Task 3: Calculate the Average

Function Name: calculate_average
Parameters:

  • total_sum: the sum of all grades
  • num_students: how many grades were entered

Returns: the average as a float.


Part 3: Main Program

In your main function:

  1. Input Grades:
    • Ask for grades until the user enters -1.
    • As each valid grade is entered, immediately add it to the running total.
    • Update counts for A, B, C, D, and F.
    • Track the highest and lowest grades.
  2. Calculate Statistics:
    • Use the running total and number of grades to calculate the average.
    • Make sure you correctly keep track of highest and lowest grades.
  3. Display Results:
    • Print counts for each grade category.
    • Print average, highest, and lowest grades.
  4. Repeat:
    • Ask if the user wants to enter another set of grades.
    • If yes, start over.

Part 4: Testing

Test your program with the following cases:

Test 1: Basic Input

85, 92, 78, -1

Expected:

Average: 85.00
Highest: 92
Lowest: 78
A’s: 1, B’s: 1, C’s: 1, D’s: 0, F’s: 0
Code language: HTTP (http)

Test 2: Boundary Values
Enter grades like 90, 89, 70, 60, 59 to check category edges.

Test 3: Invalid Input
Enter invalid grades (e.g., -5, 105) and confirm the program asks again.


Submission

Submit your Python file to OnlineGDB and Moodle.

Your program must include at the top (as comments):

  • Name
  • Email
  • Program description
  • Last modified time
  • Academic Integrity Statement

Example:

# Name: Alan Turing
# Email: turing@computerscience.edu
# Last Modified: 22 February 2025, 9:15 pm
# Program Description: This program collects student grades and reports averages and categories.
# Academic Integrity Statement: I attest that I followed the academic honesty policy of this course.
# I wrote this program myself and did not use unauthorized help.
Code language: PHP (php)

If the integrity statement is missing, the lab will not be graded.


Grading Rubric (100 points)

RequirementPoints
All features implemented40
Code organized into functions10
Clear formatting5
Good variable & function names7
Required comments (header + functions)8
Program repeats until user quits5
Correct output on all tests25

Total: 100

Scroll to Top