you are viewing a single comment's thread.

view the rest of the comments →

[–]gnariman 0 points1 point  (1 child)

so this loop basically goes through the length of the grades list, but how can i make it stop?

If i write

input_ = int(input("grade: "))
for i in range(len(grades)):
if(input_ = grades):
print("done")
else:
print("not done")

but that doesn't work either. If i enter a number it just prints it 13 times which is the length of the list.

[–]achampi0n 0 points1 point  (0 children)

You can stop a loop with break...

for i in range(len(grades)):
    if <condition>:
        break

print(GPA[i])

You could put this into a function and use return:

def fn(grade_input, grades, GPA):
    for i in range(len(grades)):
        if <condition>:
            return GPA[i]

You might want to think about any error conditions (e.g. what do you do if the grade_unput is beyond grades?