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
Zaloguj się, aby zobaczyć historię rozwiązań
Zaloguj sięZaloguj się, aby korzystać z Mentora AI
Zaloguj sięVisible tests
1
Input
"3-598-21508-8"Expected
True2
Input
"3-598-21508-9"Expected
False3
Input
"3-598-21507-X"Expected
True4
Input
"3598215088"Expected
True5
Input
"3-598-21507-A"Expected
False6
Input
"3-598-P1581-X"Expected
FalseFocus radio
Paused · SomaFM · Fluid