# Final Grades Program: how to convert number to letter for grades with method

I am trying to create a program that will: Prompt the user for the number of grades that will be entered. Take in the users name, and then their grade in two prompts. Display their letter grade for each person. Then calculate the class average, highest mark, and lowest mark from the input.

I need to have a method for the `convertGrade` (From number to letter).

Each method above should take in a list as a parameter.

The output can look something like this:

```Welcome to the Final Grades Program

Enter the number of students: 3

Student's name: t
Student's mark (%): 32

Student's name: d
Student's mark (%): 78

Student's name: r
Student's mark (%): 89

t          F
d          B
r          A

Class Average:    67
Highest Mark:     89
Lowest Mark:      32
```

However, I can’t work out how to convert number to letter for grades (because int and str don’t work with > or <) So can I get some advice on what to do?

My mess of a code:

```def intro():
name = []
mark = []

while True:
# Number of students
numStudents = input("Enter the number of students: ")
print ()

#Info (Name/grade)
for x in range(int(numStudents)):
stuName = input("Student's name: ")
stuMark = input("Student's mark (%): ")
name.append(stuName)
mark.append(stuMark)
print ()

if stuMark > 80:
print ("A")

elif stuMark > 70 and stuMark < 79:
print ("B")

elif stuMark > 60 and stuMark < 69:
print ("C")

elif stuMark > 50 and stuMark < 59:
print ("D")

elif stuMark < 50:
print ("F")

else:
print ("Could not calculate grade.")

# List
def list():
print ()
print("Student Name tt Student Grade")
print("---------------------------------------------")
for x in range(len(name)):
print(f"{name[x]} ttt {mark[x]}")

def main():
print ("Welcome to the Final Grades Program")
print()
start = intro()
show = list()

main()
```

## Answer

@Mitzy, there are some nice function in Python for this quickly lookup – eg. `bisect()` module. Try to get familiar with it. So your program can be improved here:

```import bisect

def grading(score, points=[50, 60, 70, 80], grades='FDCBA'):
i = bisect.bisect(points, score)
#print(i)
return grades[i]

def intro():
students, marks = [], []

while True:
# Number of students
numStudents = input("Enter the number of students: ")
print ()

#Info (Name/grade)
for x in range(int(numStudents)):
name = input("Student's name: ")
mark = int(input("Student's mark (%): "))
print(name, mark, grading(mark))

students.append(name)
marks.append(mark)

# List
def my_list():
print ()
print("Student Name tt Student Grade")
print("---------------------------------------------")
for x in range(len(name)):
print(f"{name[x]} ttt {mark[x]}")

if __name__ == '__main__':
print ("Welcome to the Final Grades Program")
print()
intro()
my_list()

```

Outputs:

```Welcome to the Final Grades Program

Enter the number of students: 3

Student's name: Alex
Student's mark (%): 91
Alex 91 A
Student's name: Bill
Student's mark (%): 82
Bill 82 A
Student's name: Cindy
Student's mark (%): 75

Cindy 75 B
Enter the number of students: 2
```