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

N

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)
14 views2 pages

N

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
You are on page 1/ 2

# 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 records.items():
# 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(records.values())[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 records.items():
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
records.pop(stud_id)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy