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
PostgreSQLv16

Εδώ θα εμφανιστεί το αποτέλεσμα εκτέλεσης του κώδικα

Visible tests
1
Input
"1"
ExpectedFalse
2
Input
"0"
ExpectedFalse
3
Input
"059"
ExpectedTrue
4
Input
"59"
ExpectedTrue
5
Input
"055 444 285"
ExpectedTrue
6
Input
"8273 1232 7352 0569"
ExpectedFalse
Focus radio
Paused · SomaFM · Fluid