我已经完成了前三个部分但是在最后一个部分的main.py中没有任何的思路
data.py,grade_stats.py, report.py都已经完成但是我现在对于我的main.py没有任何思路。
一下的代码的顺寻是data.py, grade_stats.py, repots.py
def get_student_grades():
""" Gets and returns the list of all student grades, as a list of strings """
student_grades = \
[
"BCIT,COMP1516,A0001000,98.5",
"BCIT,COMP1516,A0001001,56.4",
"BCIT,COMP1516,A0001002,45.6",
"BCIT,COMP1516,A0001003,96.0",
"BCIT,COMP1516,A0001004,88.7",
"BCIT,COMP1516,A0001005,74.3",
"BCIT,COMP1516,A0001006,90.1",
"BCIT,COMP1516,A0001007,99.3",
"BCIT,COMP1516,A0001008,20.2",
"BCIT,COMP1516,A0001009,85.8",
"BCIT,COMP1516,A0001010,98.5",
"BCIT,COMP1516,A0001011,56.4",
"BCIT,COMP1516,A0001012,45.6",
"BCIT,COMP1516,A0001013,96.0",
"BCIT,COMP1516,A0001014,88.7",
"BCIT,COMP1516,A0001015,74.3",
"BCIT,COMP1516,A0001016,90.1",
"BCIT,COMP1516,A0001017,99.3",
"BCIT,COMP1516,A0001018,20.2",
"BCIT,COMP1516,A0001019,85.8",
"BCIT,COMP1516,A0002201,48.5",
"BCIT,COMP1516,A0002202,86.7",
"BCIT,COMP1516,A0002203,54.6",
"BCIT,COMP1516,A0002204,96.0",
"BCIT,COMP1516,A0002205,88.7",
"BCIT,COMP1516,A0002206,74.3",
"BCIT,COMP1516,A0002207,90.1",
"BCIT,COMP1516,A0002208,99.3",
"BCIT,COMP1516,A0002209,20.2",
"BCIT,COMP1516,A0002210,85.8",
"BCIT,COMP1516,A0002211,98.5",
"BCIT,COMP1516,A0002212,56.4",
"BCIT,COMP1516,A0002213,45.6",
"BCIT,COMP1516,A0002214,96.0",
"BCIT,COMP1516,A0002215,88.7",
"BCIT,COMP1516,A0002216,74.3",
"BCIT,COMP1516,A0002217,90.1",
"BCIT,COMP1516,A0002218,99.3",
"BCIT,COMP1516,A0002219,20.2",
"BCIT,COMP1516,A0002220,85.8",
"BCIT,COMM1000,A0001000,93.1",
"BCIT,COMM1000,A0001001,71.0",
"BCIT,COMM1000,A0001002,59.8",
"BCIT,COMM1000,A0001003,91.5",
"BCIT,COMM1000,A0001004,77.6",
"BCIT,COMM1000,A0001005,84.4",
"BCIT,COMM1000,A0001006,89.1",
"BCIT,COMM1000,A0001007,95.9",
"BCIT,COMM1000,A0001008,49.2",
"BCIT,COMM1000,A0001009,88.0",
"BCIT,COMM1000,A0001010,92.2",
"BCIT,COMM1000,A0001011,59.8",
"BCIT,COMM1000,A0001012,71.4",
"BCIT,COMM1000,A0001013,88.2",
"BCIT,COMM1000,A0001014,92.3",
"BCIT,COMM1000,A0001015,77.8",
"BCIT,COMM1000,A0001016,93.5",
"BCIT,COMM1000,A0001017,94.7",
"BCIT,COMM1000,A0001018,34.6",
"BCIT,COMM1000,A0001019,87.2",
"BCIT,COMM1000,A0002201,72.1",
"BCIT,COMM1000,A0002202,81.0",
"BCIT,COMM1000,A0002203,55.8",
"BCIT,COMM1000,A0002204,76.4",
"BCIT,COMM1000,A0002205,93.3",
"BCIT,COMM1000,A0002206,56.1",
"BCIT,COMM1000,A0002207,45.1",
"BCIT,COMM1000,A0002208,95.5",
"BCIT,COMM1000,A0002209,57.4",
"BCIT,COMM1000,A0002210,81.0",
"BCIT,COMM1000,A0002211,92.1",
"BCIT,COMM1000,A0002212,59.0",
"BCIT,COMM1000,A0002213,78.3",
"BCIT,COMM1000,A0002214,92.5",
"BCIT,COMM1000,A0002215,84.2",
"BCIT,COMM1000,A0002216,77.8",
"BCIT,COMM1000,A0002217,89.3",
"BCIT,COMM1000,A0002218,90.9",
"BCIT,COMM1000,A0002219,51.5",
"BCIT,COMM1000,A0002220,89.5",
"BCIT,MATH1305,A0001000,90.9",
"BCIT,MATH1305,A0001001,66.6",
"BCIT,MATH1305,A0001002,58.3",
"BCIT,MATH1305,A0001003,79.8",
"BCIT,MATH1305,A0001004,75.6",
"BCIT,MATH1305,A0001005,86.2",
"BCIT,MATH1305,A0001006,87.0",
"BCIT,MATH1305,A0001007,97.2",
"BCIT,MATH1305,A0001008,59.5",
"BCIT,MATH1305,A0001009,86.9",
"BCIT,MATH1305,A0001010,90.5",
"BCIT,MATH1305,A0001011,61.0",
"BCIT,MATH1305,A0001012,71.0",
"BCIT,MATH1305,A0001013,90.5",
"BCIT,MATH1305,A0001014,93.1",
"BCIT,MATH1305,A0001015,64.5",
"BCIT,MATH1305,A0001016,89.9",
"BCIT,MATH1305,A0001017,92.3",
"BCIT,MATH1305,A0001018,36.2",
"BCIT,MATH1305,A0001019,89.0",
"BCIT,MATH1305,A0002201,74.5",
"BCIT,MATH1305,A0002202,78.7",
"BCIT,MATH1305,A0002203,75.0",
"BCIT,MATH1305,A0002204,89.8",
"BCIT,MATH1305,A0002205,88.5",
"BCIT,MATH1305,A0002206,49.6",
"BCIT,MATH1305,A0002207,58.5",
"BCIT,MATH1305,A0002208,65.0",
"BCIT,MATH1305,A0002209,61.2",
"BCIT,MATH1305,A0002210,85.6",
"BCIT,MATH1305,A0002211,93.5",
"BCIT,MATH1305,A0002212,61.1",
"BCIT,MATH1305,A0002213,93.5",
"BCIT,MATH1305,A0002214,98.2",
"BCIT,MATH1305,A0002215,79.1",
"BCIT,MATH1305,A0002216,88.8",
"BCIT,MATH1305,A0002217,85.8",
"BCIT,MATH1305,A0002218,94.5",
"BCIT,MATH1305,A0002219,75.9",
"BCIT,MATH1305,A0002220,82.2"
]
return student_grades
```python
def calculate_course_stats(course_id, student_grades):
"""
Calculates the statistics for a course.
:param course_id: The id of the course for which to calculate the stats, for example COMP1516.
:param student_grades: The list of student grades, as a list of strings. Each string is comma separated.
:return: A tuple that includes the number of students, average grade, median grade, minimum grade and maximum grade
"""
grades = []
index = 0
while index < len(student_grades):
student_data = student_grades[index]
student_data_list = student_data.split(",")
curr_course_id = student_data_list[1]
if curr_course_id == course_id:
grades.append(float(student_data_list[3]))
index += 1
if len(grades) > 0:
course_exists = True
average = sum(grades) / len(grades)
min_grades = min(grades)
max_grade = max(grades)
else:
course_exists = False
average = 0.0
min_grades = 0.0
max_grade = 0.0
return course_exists, average, min_grades, max_grade, len(grades)
def calculate_student_stats(student_id, student_grades):
"""
Calculates the statistics for a student.
:param student_id: The id of the student for which to calculate the stats, for example A0001001.
:param student_grades: The list of student grades, as a list of strings. Each string is comma separated.
:return: A tuple that includes the number of courses, average grade, minimum grade, maximum grade and gpa
"""
total_credits = 0.0
total_grades = 0.0
num_courses = 0
index = 0
while index < len(student_grades):
grade_info = student_grades[index].split(",")
curr_student_id = grade_info[2]
if curr_student_id == student_id:
total_credits += 1
total_grades += float(grade_info[3])
num_courses += 1
index += 1
if num_courses > 0:
min_grades = min([float(x.split(",")[3]) for x in student_grades if x.split(",")[2] == student_id])
max_grade = max([float(x.split(",")[3]) for x in student_grades if x.split(",")[2] == student_id])
average = total_grades / total_credits
if average >= 85:
gpa = 4.0
elif average >= 80:
gpa = 3.7
elif average >= 76:
gpa = 3.3
elif average >= 73:
gpa = 3.0
elif average >= 70:
gpa = 2.7
elif average >= 67:
gpa = 2.3
elif average >= 64:
gpa = 2.0
elif average >= 60:
gpa = 1.7
elif average >= 55:
gpa = 1.5
elif average >= 50:
gpa = 1.0
else:
gpa = 0.0
else:
average = 0.0
min_grades = 0.0
max_grade = 0.0
return num_courses, average, min_grades, max_grade, gpa
```python
import datetime
def display_course_statistics(course_id,
course_exists,
num_students,
average_grade,
median_grade,
min_grade,
max_grade):
"""
Displays the course statistics to the console in a report format.
If the course does not exist, displays "Course COMP1234 does NOT exist!" where COMP1234 corresponds
to the course_id.
:param course_id: The id of the course, such as COMP1516
:param course_exists: A boolean indicating if the course exists.
:param num_students: The number of students enrolled in the course
:param average_grade: The average grade of all students in the course
:param median_grade: The median grade of all students in the course
:param min_grade: The lowest grade of all students in the course
:param max_grade: The highest grade of all students in the course
"""
if not course_exists:
print(f"Course with ID {course_id} does not exist.")
else:
print(f"Report: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Course: {course_id}")
print(f"Number Students: {num_students}")
print(f"Lowest Grade: {min_grade}")
print(f"Highest Grade: {max_grade}")
print(f"Average Grade: {average_grade}")
print(f"Median Grade: {median_grade}")
def display_student_statistics(student_id,
student_exists,
num_courses,
average_grade,
min_grade,
max_grade,
gpa):
"""
Displays the students statistics to the console in a report format.
If the student does not exist, displays "Student ID A0001234 does NOT exist!" where A0001234 corresponds
to the student_id.
:param student_id: The id of the student, such as A0001234
:param student_exists: A boolean indicating if the student exists in the school
:param num_courses: The number of courses the student is enrolled in
:param average_grade: The average grade of the student over their courses
:param min_grade: The lowest grade the student has in their courses
:param max_grade: The highest grade the student has in their courses
:param gpa: The gpa of the student
"""
if not student_exists:
print(f"Student with ID {student_id} does not exist.")
else:
print(f"Report: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Student: {student_id}")
print(f"Number Courses: {num_courses}")
print(f"Lowest Grade: {min_grade}")
print(f"Highest Grade: {max_grade}")
print(f"Average Grade: {average_grade}")
print(f"GPA: {gpa}")
输出的示例
>python3 main.py invalid COMP1516
Invalid report type. Must be course or student.
> python3 main.py course
Invalid number of arguments.
> python3 main.py course COMP1516 extra
Invalid number of arguments.
> python3 main.py course COMP1516
Report: 2022-02-02 20:41:44
Course: COMP1516
Number Students: 40
Lowest Grade: 20.2
Highest Grade: 99.3
Average Grade: 75.2
Median Grade: 86.2
> python3 main.py course TEST1234
Course TEST1234 does NOT exist!
> python3 main.py student A0001000
Report: 2022-02-02 20:41:47
Student: A0001000
Number Courses: 3
Lowest Grade: 90.9
Highest Grade: 98.5
Average Grade: 94.2
GPA: 4.0
> python3 main.py student A9999999
Student ID A9999999 does NOT exist!