So I am on pset6 trying to implement the credit card check.

I've already completed working through the numbers and am not having any issue with the actual algorithm.

But for some reason my if statements logic doesn't work.

if ((foo)%10 == 0):
    a = True
    a = False


if (a == True and r[0] == 4):
elif(a == True and r[0] == 3 and r[1] == 4 or 7):
elif(a == True and r[0] == 5 and r[1] == 1 or 2 or 3 or 4 or 5):

See here

Even though I've set the logic up to only recognize as a Amex if r[0] is 3 and r[1] is 4 or 7. It still shows up as an AMEX. I have also printed out r[0] and r[1] so I can show you that the values within that index are correct.

I don't understand how this can ignore my logic statements and print anyway. Please help me understand what I have done incorrectly. Thank you for your time.

  • Am I not providing enough information or something? I'd really like to figure out what I am doing wrong here. – Multiplify May 3 at 13:16

This elif(a == True and r[0] == 3 and r[1] == 4 or 7): will always evaluate to True because 7 is "truthy". Did you mean or r[1] == 7? And once an or introduced, the expression will likely need parentheses. Same goes for the subsequent elif.

  • Hmm, I'm not sure I understand what you mean by 7 evaluating as truthy. So should I re-write the code as r[1] == 4 or ==7 or do I need to write r[1] == 4 or r[1] == 7? I'll go and test it now. When we are writing or statements do we need to re-iterate the element every time? Is there a better way for me to write if r[1] is within 1-5 do something – Multiplify May 3 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .