I am writing a code that creates a list that stores multiple Course names. There is another list that stores student names and their scores. I am trying to generate a report that will show all the courses and the total of student scores from the list.

I tried creating a third list that will store the different course with student name and their score and then display only the course and total score of students offering the course.

def menu():

    choice = input("""
    1: Enter course
    2: Enter score figure
    3: Generate report

    Please enter your choice: """)
    print("------------------------------------------------------------")

    if choice == "1" :
            entercoursedetails()
    elif choice == "2":
            enterstudentdetails()
    elif choice == "3":
            generatereport()
    else:
            print("You must only select either 1,2 or 3.")
            print("Please try again")
            menu()

def entercoursedetails():
    #user is prompted to input all the required fields
    print("Enter course name")
    coursename=input()

    if (coursename not in Currentcourse) :
             Currentcourse.append(coursename)
             informationList.append(coursename)# {record all course names}

    index = Currentcourse.index(coursename)        

   return coursename

menu()        

def enterstudentdetails():

    name_array = list()
    score_array = list()

    print ("score Reporting")
    print (" Current course:", Currentcourse)
    def check_continue():


        response = input('Continue? [y/n] ')

        if response == 'n':
            return False
        elif response == 'y':
            return True
        else:
            print('Please select a correct answer [y/n]')
            return check_continue()


    while(True):

        std_name = input('Name: ')
        score_record = int(input('score: '))

        name_array.append(std_name)
        score_array.append(score_record)

        if not check_continue():
            break
        else:
            continue

    for name, score in zip(name_array, score_array):
        print(name, '\t', score)


def generatereport():
    persum = [0 for i in range(100)] 
    for item in informationList :


        persum[Currentcourse.index(item[1])] += float(item[2]) 

    for i in range (len(Currentcourse)) :     
        print(Currentcourse[i], "    ", persum[i])
        print("-----------------------------")

    for item in informationList :
        print(item[0], "   ", item[2])

    print("-----------------------------")
    print("Total Score:     ", sum(persum))
    print("-----------------------------")

when Generate report is selected, its meant to show

_____________________
Maths        | 98   |

Science      | 30.5 |
_____________________
Peter        | 52   |

Paul         | 46   |

Abba         | 30.5 |
_____________________
Total sales  | 128.5|
_____________________

Peter and Paul are offering only maths. abba is offering only science.

0 Answers