You are viewing a single comment's thread. Return to all comments →
here is my code without regex because i don't know what that is
`num = int(input()) i = 0 credits = [None] * num while (i < num): credits[i] = input() i += 1 for credit in credits: if credit[0] not in "456": print ("Invalid") continue count = 0 digit = False is_16_digit = False is_consecutive = False hyphen_count = 0 for c in credit: if c.isdigit(): count +=1 digit = True elif c == "-" and count % 4 == 0: hyphen_count += 1 continue else: digit = False break if count == 16: is_16_digit = True credit = credit.replace("-","") for c in credit: if c+c+c+c in credit: is_consecutive = True break if is_16_digit == False: print("Invalid") continue elif digit == False: print("Invalid") continue elif is_consecutive: print("Invalid") continue elif hyphen_count > 3: print("Invalid") continue else: print("Valid")
`
Seems like cookies are disabled on this browser, please enable them to open this website
Validating Credit Card Numbers
You are viewing a single comment's thread. Return to all comments →
here is my code without regex because i don't know what that is
`