I have this little credit card validation program where the user has to input an 8 digit integer. The program works fine, my only problem seems to be limiting user input to 8 digits only.
prompt = "Please, enter the 8 digit number of your card: "
while True:
try:
userinput = int(raw_input(prompt))
except ValueError:
print('The gematric value must be an 8 digit integer. Try again')
else:
break
userinput = str(userinput)
a = int(userinput[7])+int(userinput[5])+int(userinput[3])+int(userinput[1])
b1 = str(int(userinput[6])*20)
b2 = str(int(userinput[4])*20)
b3 = str(int(userinput[2])*20)
b4 = str(int(userinput[0])*20)
y = int(b1[0])+int(b1[1])+int(b2[0])+int(b2[1])+int(b3[0])+int(b3[1])+int(b4[0])+int(b4[1])
x = (a+y)
if x % 10 == 0:
print('The card number you entered is valid!')
else:
print('The card number you entered is invalid!')
I know len() does not work with integers. So how would i incorporate that 8 digit limit into my while true loop?
Any help would be appreciated.