2

One thing first, and has higher precedence than or. 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 ...


2

Python doesn't have a long long type. You can use get_int to hold your credit card number.


1

The Luhn's algorithm says you must add together the sum of the digits when multiplying by 2. So if your card number digit is 8, for example, 8 * 2 is 16, so you need to add 1+6 to your sum, not 16.


1

Unlike C, / will perform true floating point division in Python. To get integer division (and discard the remainder), use // instead. Regarding being stuck in the for loop, range(num) will loop all the way up to the actual value of num (over four quadrillion iterations for a typical VISA!). Perhaps try something like: while num > 0: One small note: sum ...


1

Looks like one step in Luhn's is missing: Multiply every other digit by 2, starting with the number’s second-to-last digit, and then add those products’ digits together.


1

Python 3 separated integer division // and floating point division / operators. You probably want to use the former (note that it truncates the result, so you might have to use (length + 1) // 2 for rounding up). Oh, and there's //= operator, too. Something about the nested loops makes me feel uncomfortable. I don't understand them, or why one would want ...


1

I don't see how while cardNo>0: could not cause an infinite loop. And don't use eval, it's evil.


1

Check this simple program, and see what happens when you get a float from the user using get_float() and then cast it to str. See what is wrong with it and how your program fails? import cs50 def main(): x = cs50.get_float("Number: ") print(str(x)) if __name__ == "__main__": main() Output: Number: 20 20.0 Also, your program is full of "...


Only top voted, non community-wiki answers of a minimum length are eligible