0

Credit card validator (need help)

Why I don't make test 3,4 , where I wrong? Почему не получается пройти тест 3, 4. Где ошибка? card=list(input()) stand=["1","2","3","4","5","6","7","8","9","0"] for y in card: if y not in stand: print("not valid") break elif y in stand: rev_card=card[::-1] x=0 sec_card=[] big=[] for i in rev_card: c=i x+=1 if x%2==1: c2=int(c) c2*=2 sec_card.append(c2) for b in sec_card: b2=int(b) if b2>9: b2-=9 big.append(b2) all_sum=sum(big) if all_sum%10==0 and len(big)==16: print("valid") break else: print("not valid") break

21st Feb 2023, 12:37 PM
Galina Van
17 Respostas
+ 2
Is that this code coach? You need to verify if the given credit card number is valid. For that you need to use the Luhn test. Here is the Luhn formula: 1. Reverse the number. 2. Multiple every second digit by 2. 3. Subtract 9 from all numbers higher than 9. 4. Add all the digits together. 5. Modulo 10 of that sum should be equal to 0. Task: Given a credit card number, validate that it is valid using the Luhn test. Also, all valid cards must have exactly 16 digits. Input Format: A string containing the credit card number you need to verify. Output Format: A string: 'valid' in case the input is a valid credit card number (passes the Luhn test and is 16 digits long), or 'not valid', if it's not. Sample Input: 4091131560563988 Sample Output: valid
21st Feb 2023, 2:44 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
I took the sample Input and put it into your code and received "not valid". I then went through and added print statements to see what the code does. I think you have 2 indentation errors. Check the line sec_card.append(c2) and big.append(2). I also changed the len(big) to len(card) but I don't think that affects the result other than I like to check the original input instead of whatever is left after all the work your code does.
21st Feb 2023, 2:59 PM
Ausgrindtube
Ausgrindtube - avatar
21st Feb 2023, 3:30 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
I'm sorry, I don't understand that. The sample input prints valid, so it shouldn't be cutting any numbers.
21st Feb 2023, 3:42 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Ausgrindtube, yes, this code
21st Feb 2023, 2:46 PM
Galina Van
+ 1
I don't understand last words about check... About checking two line, I don't know, where I can move this line, do you have ideas? I try move this line to the left, no affects. Move to the right, error.
21st Feb 2023, 3:10 PM
Galina Van
+ 1
Sorry, you help, I see what all number of card multiply 2 🙏🙏🙏
21st Feb 2023, 3:40 PM
Galina Van
0
Thanks for the attention, but don't help, if move two line to the right, cut number of card😢
21st Feb 2023, 3:37 PM
Galina Van
0
If move line to the right, program take in list sec_card only number, which true of operator if.
21st Feb 2023, 3:48 PM
Galina Van
21st Feb 2023, 5:22 PM
Smith Welder
Smith Welder - avatar
0
Smith Welder Интересно, но ничего не понятно, я не сильна в таких лаконичных кодах🙀 Скопировала в окно проверки, чёт все равно не то😳
21st Feb 2023, 5:33 PM
Galina Van
0
Smith Welder спасибо, я ступила и не так как надо скопировала. Всё правильно написано, просто я баран 😢
21st Feb 2023, 5:38 PM
Galina Van
0
Что именно не понятно?
21st Feb 2023, 5:44 PM
Smith Welder
Smith Welder - avatar
0
Честно, весь код, и что там обозначено, мой уровень очень низкий, такого уровня кодировки никогда не видела...
21st Feb 2023, 5:50 PM
Galina Van
0
Что такое g? u первоначальное значение цифр номера карты x так понимаю это каждая цифра номера карты после вычислений
21st Feb 2023, 5:52 PM
Galina Van
0
g это порядковый номер цифры числа. Функция enumerate() пронумировывает всю строку от нуля и до конца. Используйте функцию print() , если что либо не понятно. print(g)
21st Feb 2023, 6:01 PM
Smith Welder
Smith Welder - avatar
0
Спасибо за исчерпывающий ответ😊🤝
21st Feb 2023, 10:01 PM
Galina Van