[go: up one dir, main page]

0% found this document useful (0 votes)
42 views2 pages

Student Grade Management System

Uploaded by

faresimfree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Student Grade Management System

Uploaded by

faresimfree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

# define a function to show the average grade for all students

def show_all_averages(records):
# print header for the table
print("\n" + "StudentID".ljust(15) + "Student Name".ljust(20) + "Average")

# loop through each student record and calculate their average grade
for stud_id, student_info in [Link]():
# calculate average grade for the student
average = sum(student_info['grades']) / len(student_info['grades'])
# round the average grade to one decimal place
average = round(average, 1)
# print the student's ID, name, and average grade
print(stud_id.ljust(15) + student_info['name'].ljust(20) + "%s" % average )

# define a function to add a new student with test grades


def add_student(records):
# prompt the user to enter a new student ID
stud_id = input("Enter the new student ID: ").strip()
# check if the student ID already exists in the records
if stud_id in records:
# print error message if the student ID already exists
print("Error: Student ID already exists")
else:
# prompt the user to enter the student's name
student_name = input("Enter the student's name: ").strip()
# initialize an empty list for the new test scores
new_scores = []
# determine the number of tests based on the number of grades in the first
student record
if records:
test_count = len(list([Link]())[0]['grades'])
else:
test_count = 1
# Loop through each test and prompt the user to enter a grade
for i in range(1, test_count + 1):
while True:
score = input("Enter grade for Test#%s" % i + ": ")
try:
score = float(score)
# Check if the score is between 0 and 100
if 0 <= score <= 100:
# Add the score to the new_scores list if it's valid
new_scores.append(score)
break
else:
# Print error message if the score is invalid
print("Invalid grade")
except ValueError:
# Print error message if the input is not a valid number
print("Invalid grade")
# Add the new student record to the records dictionary
records[stud_id] = {'name': student_name, 'grades': new_scores}

# Update specific student grade for


def update_student_score(records):
# Prompt user to enter student ID to update the score
stud_id = input("Please enter student ID: ").strip()
# Check if the student ID exists in the records dictionary
if stud_id not in records:
print("Error: Invalid student ID")
input("\nPress Enter key to continue . . .")
return

# Prompt user to enter the quiz number to modify


quiz_num = int(input("Please enter quiz number to modify: ").strip())
student_info = records[stud_id]

# Check if the quiz number is valid for the student


if 0 < quiz_num <= len(student_info['grades']):
# Prompt user to enter the new quiz score
new_score = float(input("Please enter new quiz grade: ").strip())
# Update the quiz score for the student
student_info['grades'][quiz_num - 1] = new_score
else:
# Quiz number is not valid, return from function
return

# Add new test grades for all students


def input_test_grades(records):
# Prompt user to enter test grades for all students
print("Please enter test grades for the next test")
for stud_id, student_info in [Link]():
while True:
# Prompt user to enter grade for each student
score = input("Please enter grade for student %s" % stud_id + ":")
try:
# Convert input to float and check if grade is valid
score = float(score)
if 0 <= score <= 100:
# Add the grade to the student's grades list
student_info['grades'].append(score)
# Exit the while loop
break
else:
# Invalid grade, prompt user to enter grade again
print("Invalid grade")
except ValueError:
# Invalid input, prompt user to enter grade again
print("Invalid grade")

# Remove a student
def remove_student(records):
# Prompt user to enter student ID to remove
stud_id = input("Enter the student ID to delete: ").strip()
if stud_id not in records:
# Student ID is not valid, print error message
print("Error: Invalid Id")
else:
# Remove the student from the records dictionary
[Link](stud_id)

You might also like