Below is my code:
output is: Enter the card number: 378282246310005 firstTwo 37; firstOne 3; cardlen 15 MASTERCARD
note: it shows MASTERCARD instead of AmEx..Why?
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.Sign up to join this community
One thing first,
and has higher precedence than
A or B and C is same as
A or (B and C). Keep that in mind when combining the two.
In Python, pretty much like in C,
firstTwo == 51 or 52 or 53 or 54 or 55 is interpreted as
(firstTwo == 51) or (52) or (53) or (54) or (55), five expressions combined with
or. As all but the first (which may or may not) are always truthy, the whole condition will always trigger.
Correct would be for example
firstTwo in [51, 52, 53, 54, 55], or
51 <= firstTwo <= 55 (that one did not work in C, where comparison operators cannot be chained).