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
Pieslēdzies, lai redzētu iesniegumu vēsturi
PieslēgtiesPieslēdzies, lai izmantotu AI mentoru
PieslēgtiesVisible tests
1
Input
"1"Expected
False2
Input
"0"Expected
False3
Input
"059"Expected
True4
Input
"59"Expected
True5
Input
"055 444 285"Expected
True6
Input
"8273 1232 7352 0569"Expected
FalseFocus radio
Paused · SomaFM · Fluid