0

I have attempted to use regex matching to solve the credit problem, but I am encountering the problem of syntax error when trying to run my code. The regex.match function I tried to use was found from a stackoverflow post that I thought would be apt for matching the conditional credit card numbers, so I dont really understand why the error is appearing.

from cs50 import get_int
import re

def main ():

    ccn= get_int("Enter your credit card number: ")
    no= str(ccn)
    length= len(no)
    while (length == 13 or 15 or 16):
        fax = checkm8(ccn)
        match1='^34(\D{13})'
        match2='^37(\D{13})'
        match3='^5[1-5](\D{14}'
        if (any (regex.match(ccn) for regex in [match1,match2]== True) and fax== True):
            print("AMEX\n")

        elif (any regex.match(ccn) for regex in [match3]== True) and fax==True):
            print("MASTERCARD\n")

        elif(ccn>=4e12 and ccn<5e12) or(ccn>=4e15 and ccn<4e15) and fax==True):
            print("VISA\n")
        else:
            print("INVALID\n")
        break





def checkm8(number):
    length= len(str(number))
    for i in range(-1,length,-2):
        total_1=0
        total_1+= i
    for no in range(-2,1-length, -2):
        total_2= 0
        digit=no*2
        total_2= digit/10 + digit%10

    dawg = (total_1 + total_2)%10
    if (dawg== 0):
        return True
    else:
        return False




if __name__ == "__main__":
    main()

Any help would be greatly appreciated!

1
  • at a quick glance, any is a function which requires argument in parentheses. May 1 at 13:15

You must log in to answer this question.

Browse other questions tagged .