MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_valid

Function is_valid

strings/barcode_validator.py:35–53  ·  view source on GitHub ↗

Checks for length of barcode and last-digit Returns boolean value of validity of barcode >>> is_valid(8718452538119) True >>> is_valid(87184525) False >>> is_valid(87193425381089) False >>> is_valid(0) False >>> is_valid(dwefgiweuf) Traceback (most r

(barcode: int)

Source from the content-addressed store, hash-verified

33
34
35def is_valid(barcode: int) -> bool:
36 """
37 Checks for length of barcode and last-digit
38 Returns boolean value of validity of barcode
39
40 >>> is_valid(8718452538119)
41 True
42 >>> is_valid(87184525)
43 False
44 >>> is_valid(87193425381089)
45 False
46 >>> is_valid(0)
47 False
48 >>> is_valid(dwefgiweuf)
49 Traceback (most recent call last):
50 ...
51 NameError: name 'dwefgiweuf' is not defined
52 """
53 return len(str(barcode)) == 13 and get_check_digit(barcode) == barcode % 10
54
55
56def get_barcode(barcode: str) -> int:

Callers 1

Calls 1

get_check_digitFunction · 0.85

Tested by

no test coverage detected