Check with Luhn
The Luhn algorithm is used for quick validation of numeric codes, helping catch accidental digit mistakes. The function valid receives a string card_num and checks it with this algorithm, ignoring spaces. A string with only one digit, or with any characters other than digits and spaces, is invalid.
Примеры
Ввод
"1"Вывод
FalseВвод
"0"Вывод
FalseВвод
"059"Вывод
TrueНужно реализовать
def valid(card_num: str) -> bool:
Теги
stringsmath
Přihlaste se, abyste viděli historii odevzdání
Přihlásit sePřihlaste se, abyste mohli použít AI mentora
Přihlásit seTests12
Visible tests
Skrytý test 7
Skrytý test 8
Skrytý test 9
Skrytý test 10
Skrytý test 11
Skrytý test 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid