0
사용자가 8 자리 정수를 입력해야하는이 작은 신용 카드 확인 프로그램이 있습니다. 프로그램이 잘 작동, 내 유일한 문제는 8 자리 숫자로 사용자 입력을 제한하는 것으로 보인다.사용자 정수 입력을 8 자리로 제한
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!')
정수형에서는 len()이 작동하지 않습니다. 그렇다면 실제 루프 동안 8 자리 제한을 어떻게 통합 할 수 있습니까?
도움을 주시면 감사하겠습니다.
위대한, 내가 방금! =로 변경하고 완벽하게 작동합니다. 고맙습니다. – Manifold