Check ISBN Codes

ISBN-10 is checked with a special checksum, which helps catch mistakes in the digits. The function is_valid receives an isbn string: hyphens should be ignored, and the last character may be X, meaning 10. After calculating d1*10 + d2*9 + ... + d10*1, the total must be divisible by 11 with no remainder.

Примеры

Ввод
"3-598-21508-8"
Вывод
True
Ввод
"3-598-21508-9"
Вывод
False
Ввод
"3-598-21507-X"
Вывод
True

Нужно реализовать

def is_valid(isbn: str) -> bool:

Теги

stringsmath
PostgreSQLv16

Siia ilmub koodi käivituse tulemus

Visible tests
1
Input
"3-598-21508-8"
ExpectedTrue
2
Input
"3-598-21508-9"
ExpectedFalse
3
Input
"3-598-21507-X"
ExpectedTrue
4
Input
"3598215088"
ExpectedTrue
5
Input
"3-598-21507-A"
ExpectedFalse
6
Input
"3-598-P1581-X"
ExpectedFalse
Focus radio
Paused · SomaFM · Fluid