mardi 2 août 2016

Python If statment-differences

I try to learn the If statement forms integrated with For loop type, and i can't understand the differences between these 2 codes because they give the same result:

grade = [100, 97, 73, 56, 78,34]
for i in range(0,len(grade)):
    if grade[i]%2 == 0:
        grade[i]= grade[i]+2
    if grade[i]%3 ==0:
        grade[i]= grade[i]+3
    if grade[i]%5 ==0:
        grade[i]= grade[i]+5
print grade

and this:

grade = [100, 97, 73, 56, 78,34]
for i in range(0,len(grade)):
    if grade[i]%2 == 0:
        grade[i]= grade[i]+2
        if grade[i]%3 ==0:
                grade[i]= grade[i]+3
            if grade[i]%5 ==0:
                grade[i]= grade[i]+5
print grade

Aucun commentaire:

Enregistrer un commentaire