Contributors: Chris Chen, David Chen
This program take the pre-defined student names and their corresponding grades and displays the average. After that, the program allows the user add their own student names and averages.
Sample Inputs and Output:
Explanation of Code
Line 18: Import the "os" module to clear the screen after each loop, enhancing readability.
Lines 21-24: Initialize variables: "students" (a list with default student names), "student_grades" (a list with default corresponding grades), "user_input" (to store user inputs), "input_grade" (to store inputted grades), and "index" (used in the while loop to output each grade).
Line 26: This loop continuously executes, allowing users to input student names and grades, updating the list, and displaying the output until terminated with "q" input.
Line 28: Clear the screen using the ".system("clear")" method from the os module.
Line 32: Initiate a loop where "student" iterates over elements in the "students" list, enabling operations on individual students.
Line 34: Print the current student's name accessed via the "student" variable from line 32.
Line 40: Reset the "index" variable to 0 before each while loop iteration.
Line 44: Use a while loop that continues while "index" is less than the length of "students", facilitating iteration through the list to output each grade.
Line 46: Print the student's grade accessed from the "students_grades" list using the "index" variable.
Line 49: Increment "index" after each loop iteration to move to the next item in "students_grades".
Line 56: Initialize another loop where "i" iterates over the range of items in the "students" list using the "len()" function.
Line 58: Print each student's name concatenated with their corresponding grade accessed with the "i" variable.
Line 64: Calculate the average grade for all students using the "sum()" function of "student_grades" divided by the number of grades (obtained using "len()"), rounded to the nearest percent.
Line 67: Print a message displaying the average grade to the user.
Line 73: Prompt the user to enter a student's name and store it in the "user_input" variable.
Lines 76-80: Check if the user input is "q"; if so, break the loop and exit the program. Otherwise, append the student name to the "students" list.
Line 83: Prompt the user to enter a student's grade and store it in the "user_input" variable.
Lines 86-90: Check if the user input is "q"; if so, break the loop and exit the program. Otherwise, convert the user input to an integer using the "int()" function and append it to the "students_grades" list.
*If the program doesn't break, it loops back to line 28 to re-iterate the loop.
Line 93: Print a message to tell the user the program has stopped.
Give the program a try here: https://replit.com/@ChrisChen42/AverageMarkV2?v=1