I'm new to using python and wanted to know how I could improve my program. I'm using the Luhn algorithm, the beginning numbers of the credit cards, and the number of digits in the credit card.
from cs50 import get_string
import re
import sys
number = get_string("NUMBER: ")
check = []
if (len(number)) not in (13,15,16):
print("INVALID")
print(len(number))
sys.exit(1)
for i in range(len(number)): # for the length of the string,
if i%2 == (-2+len(number))%2: # if a counter is modulo 1
digits = str(int(number[i])*2) #obtains the value of the multiplication
for j in range(len(digits)):
check.append(int(digits[j]))
else:
check.append(int(number[i]))
total = str(sum(check))
if re.search("0$", total):
if re.search("^3(4|7)", number):
print("AMEX")
elif number[0] == str(4):
print("VISA")
elif re.search("^5(1|2|3|4|5)", number):
print("MASTERCARD")
else:
print("INVALID")