Nov-04-2018, 01:03 PM
Hello,
I have been trying to make a credit card validator but i keep getting an error. I have created a special fuction that removes the empty spaces and "-"s from the string.
I have been trying to make a credit card validator but i keep getting an error. I have created a special fuction that removes the empty spaces and "-"s from the string.
def checker(string):
for i in range (len(string)):
if " " in string:
string = string.replace(' ','')
elif "-" in string:
string = string.replace('-','') This is my total codedef digit_sum(LIST):
for i in range(len(LIST)):
value = str(LIST[i])
digits = [int(x) for x in value]
credit_card.append(sum(digits))
def checker(string):
for i in range (len(string)):
if " " in string:
string = string.replace(' ','')
elif "-" in string:
string = string.replace('-','')
credit_card=[]
credit_card_sum=[]
credit_card_sum_digit=[]
credit_digits_sum=0
user_input=input()
checker(user_input)
while user_input!="end" and user_input!="END":
credit_card_str=str(user_input)
credit_card_int=[int(x) for x in credit_card_str]
if credit_card_int[0]<4 or credit_card_int[0]>7:
print ("False")
else:
for i in range(len(credit_card_int)):
if not (i% 2):
credit_card_int[i] = credit_card_int[i]*2
digit_sum(credit_card_int)
for i in range(len(credit_card)):
credit_digits_sum=credit_digits_sum+credit_card[i]
if credit_digits_sum % 2 ==0:
print ("True")
else:
print ("False")
user_input=input() If you try to run in with the input 5497-3571-7063-2130 or 54 97357 170632 130 You will get an error like this. Should i reconvert the string to STR?
