vendredi 2 juillet 2021

Calling one list from a multi-list variable: Why isn't the print statements inside if statements not printing?

I'm trying to create a function that produces the finalized grades. This function should multiply the course grades by the course bonus, so the first course list ([55,21,30,58,49]) should be multiplied by 1.0 and so on, and the same thing is done to the exam grades but with the exam bonus instead. Then it multiplies the adjusted exam and course grades together to give the total grade. The print statements inside of the if statements are not printing, I've already looked through similar questions about print() not working, but nothing seemed relevant.

NOTE: I cannot change the main program

def finalized_grades(course_grades, exam_grades, course_exam_bonus, exam_bonus):
    adj_course = []
    adj_exam = []
    total = []
    print('Before update:')
    print('Coursework = {}'.format(course_grades))
    print('Exams = {}'.format(course_grades))
    print('Course Bonus = {},'.format(course_exam_bonus),end=' ')
    print('Exam Bonus = {}'.format(exam_bonus))
    print('After update:')
    for c in course_grades:
        if c == [0]:
            adj_course = [x*course_exam_bonus[0] for x in course_grades[c]]
            print('Coursework = {}'.format(adj_course))
        if c == [1]:
            adj_course = [x*course_exam_bonus[1] for x in course_grades[c]]
            print('Coursework = {}'.format(adj_course))
        if c == [2]:
            adj_course = [x*course_exam_bonus[2] for x in course_grades[c]]
            print('Coursework = {}'.format(adj_course))
    for e in exam_grades:
        if e == [0]:
            adj_exam = [x*exam_bonus[0] for x in exam_grades[e]]
            print('Exams = {}'.format(adj_exam))
        if e == [1]:
            adj_exam = [x*exam_bonus[1] for x in exam_grades[e]]
            print('Exams = {}'.format(adj_exam))
        if e == [2]:
            adj_exam = [x*exam_bonus[2] for x in exam_grades[e]]
            print('Exams = {}'.format(adj_exam))
    for t in adj_exam:
        total = [adj_exam[t]*adj_course[t]]
        print('Total = {}'.format(total))
    return

################################# MAIN PROGRAM #################################### 
def test_finalized_grades():
    course_grades = [[55,21,30,58,49], [47,39,29], [43,32,28,60]]
        exam_grades = [[35,14, 32,18,31] , [32,32,19], [15,21,24,39]]
        course_exam_bonus = [1.0,1.25,1.2]
        exam_bonus = [3.0,0.0,2.0]
        for i in range(len(exam_bonus)):
            grades = finalized_grades(course_grades[i],exam_grades[i],course_exam_bonus[i],exam_bonus[i])
    return

This is what my output looks like

Before update:
Coursework = [55, 21, 30, 58, 49]
Exams = [55, 21, 30, 58, 49]
Scale = 1.0, Bonus = 3.0
After update:
Before update:
Coursework = [47, 39, 29]
Exams = [47, 39, 29]
Scale = 1.25, Bonus = 0.0
After update:
Before update:
Coursework = [43, 32, 28, 60]
Exams = [43, 32, 28, 60]
Scale = 1.2, Bonus = 2.0
After update:

There should be statements in-between 'Before update' and 'After update'. This is what it should look like.

Before update:
Coursework = [55, 21, 30, 58, 49]
Exams = [35, 14, 32, 18, 31]
Scale = 1.0, Bonus = 3.0
After update:
Coursework = [55.0, 21.0, 30.0, 58.0, 49.0]
Exams = [38.0, 17.0, 35.0, 21.0, 34.0]
Total = [93.0, 38.0, 65.0, 79.0, 83.0]

Aucun commentaire:

Enregistrer un commentaire