lundi 7 mai 2018

Python 3 using an if statement to read the values in 1 array and append another value to another array

Hi I am new to python and trying to write a program that reads the integer values stored in the array (percent) then based on there value using an if statement append a string to the array (grade).

The code seems to be reading the array (percent) but not storing the correct value in the (grade) array. I have been stuck on this for hours now and cant seem to find an answer that solves the problem. Here is my code

percent = [33, 44, 55, 66, 77, 88, 99]
grade = []

for i in range(0, len(percent)):
    if i >= 70 and i <= 100:
        grade.append("Grade A")
    elif i >= 60 and i <= 69:
        grade.append("Grade B")
    elif i >= 50 and i <= 59:
        grade.append("Grade C")
    elif i >= 45 and i <= 49:
        grade.append("Grade D")
    else:
        grade.append("No grade achieved")

print(grade)

All that is prints out is "No grade achieved" even though the values do not match that. Can anyone tell me what I am doing wrong here? Thank you

Aucun commentaire:

Enregistrer un commentaire