-1

Where did I make a mistake? Because the program should take only one name and one grades for each student. Exercies - Given a list of students and the points they achieved over the course of the semester, calculate their final grades and print them to the screen according to the grade scale:


list_students = ["Alice", "Bernard", "Charles", "Daniel", "Elisa",
                 "Fabian", "Gabrielle", "Helga", "Ilse", "Johann"]
list_points = [86, 73, 56, 79, 48, 98, 95, 40, 81, 88]

for x in list_students:
     for i in range(len(list_points)): 
        if list_points[i] < 50:
            i = 5
        elif list_points[i] < 63:
            i = 4
        elif list_points[i] < 75:
            i = 3
        elif list_points[i] < 87:
            i = 2
        elif list_points[i] < 100: 
            i = 1
        print(str(x) + ": " + str(i))

ann99
  • 13
  • 4
  • Welcome to SO! Please read [How to Ask](https://stackoverflow.com/help/how-to-ask), which explains how to ask a good question. Your question already contains a minimal working example, but sadly as an image - which we cannot copy onto our machines. You can edit your question to insert the code as text instead. – Nelewout Apr 25 '20 at 09:47
  • What is your expected output? – DirtyBit Apr 25 '20 at 09:47
  • 1
    the name of each student and his/her respective grade: name_of_student_1 : grade_1 – ann99 Apr 25 '20 at 09:49
  • This problem is covered nicely in [the docs for the `bisect` module](https://docs.python.org/3/library/bisect.html#other-examples). – Nelewout Apr 25 '20 at 10:02

2 Answers2

0

You probably need something like this:

for i in range(len(list_points)): 
    if list_points[i] < 50:
        grade = 'E'
    elif list_points[i] < 63:
        grade = 'D'
    elif list_points[i] < 75:
        grade = 'C'
    elif list_points[i] < 87:
        grade = 'B'
    elif list_points[i] < 100: 
        grade = 'A'
    print(list_students[i] + ": " + grade)
iamvegan
  • 482
  • 4
  • 15
-1

OP: the name of each student and his/her respective grade: name_of_student_1 : grade_1

Using zip():

list_students = ['Alice', 'Bernand', 'Charles', 'Daniel', 'Elisa',
                 'Fabian', 'Gabrielle', 'Helga', 'Ilse', 'Johann']
list_points = [86, 73, 56, 79, 48, 98, 95, 40, 81, 88]

for student, point in zip(list_students, list_points):
    print(student, ':', point)

OUTPUT:

Alice : 86                                                                                                                                                                   
Bernand : 73                                                                                                                                                                 
Charles : 56                                                                                                                                                                 
Daniel : 79                                                                                                                                                                  
Elisa : 48                                                                                                                                                                   
Fabian : 98                                                                                                                                                                  
Gabrielle : 95                                                                                                                                                               
Helga : 40                                                                                                                                                                   
Ilse : 81                                                                                                                                                                    
Johann : 88

EDIT:

Considering printing the grades:

list_students = ['Alice', 'Bernand', 'Charles', 'Daniel', 'Elisa', 'Fabian', 'Gabrielle', 'Helga', 'Ilse', 'Johann']
list_points = [86, 73, 56, 79, 48, 98, 95, 40, 81, 88]
grades = []

for point in list_points:
    if point <= 100 and point >= 87:
        grades.append('A')
    elif point < 87 and point >= 75:
        grades.append('B')
    elif point < 75 and point >= 63:
        grades.append('C')
    elif point < 60 and point >= 50:
        grades.append('D')
    elif point < 50:
        grades.append('E')


for student, point, grade in zip(list_students, list_points, grades):
    print(student, ':', point, ':', grade)

OUTPUT:

Alice : 86 : B                                                                                                                                                               
Bernand : 73 : C                                                                                                                                                             
Charles : 56 : D                                                                                                                                                             
Daniel : 79 : B                                                                                                                                                              
Elisa : 48 : E                                                                                                                                                               
Fabian : 98 : A                                                                                                                                                              
Gabrielle : 95 : A                                                                                                                                                           
Helga : 40 : E                                                                                                                                                               
Ilse : 81 : B                                                                                                                                                                
Johann : 88 : A   
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
  • Thank you very much for your help, could i ask you to help me with the second part, meaning that points attached to each student have to graded according to the scale given – ann99 Apr 25 '20 at 10:00
  • @ann99 edited and added with the grades. – DirtyBit Apr 25 '20 at 10:13
  • 1
    these are my first steps in programming, so thank you very much! now it's working perfect – ann99 Apr 25 '20 at 10:15
  • @ann99 no worries, glad it helped! ^^ – DirtyBit Apr 25 '20 at 10:20
  • can I ask you how to how to start the code or what function to use to calucate: the percentage of students that have passed the course (grade D or higher) and the percentage of students that have failed grade E? – ann99 Apr 25 '20 at 10:44
  • @ann99 I will try to explain and you can try coding, percentage = num_of_grades/total_num * 100. So if you want to find the percentage of students that passed with grade D. total_D_grades/total_students * 100. – DirtyBit Apr 25 '20 at 10:52
  • 1
    Thank you for your help i managed to complete the task! – ann99 Apr 25 '20 at 16:10