vendredi 15 décembre 2017

If statements letting wrong statements pass python [duplicate]

This question already has an answer here:

Issue

If-statements are letting a condition through even though it doesn't fit the parameter

Description

This piece of code is supposed to run when the selection is equal to either index 2 of the list operations or index 3 of the list. Yet when selection is equal to index 1 of the list operations the code still runs

if v.selection == v.operations[2] or v.operations[3]:
    print('arrived at a sub n missing - geometric')
    print('index of ', v.selection, 'in the list is ', v.operations.index(v.selection))
    if not v.aSub1:
        v.aSub1 = input('first value in sequence>>>')
    if not v.r:
        v.r = input('common rate>>>')
    if not v.n:
        v.n = input('index (n)>>>')
        pass
    pass
pass

output

Aucun commentaire:

Enregistrer un commentaire