Returns the barcode as an integer >>> get_barcode("8718452538119") 8718452538119 >>> get_barcode("dwefgiweuf") Traceback (most recent call last): ... ValueError: Barcode 'dwefgiweuf' has alphabetic characters.
(barcode: str)
| 54 | |
| 55 | |
| 56 | def get_barcode(barcode: str) -> int: |
| 57 | """ |
| 58 | Returns the barcode as an integer |
| 59 | |
| 60 | >>> get_barcode("8718452538119") |
| 61 | 8718452538119 |
| 62 | >>> get_barcode("dwefgiweuf") |
| 63 | Traceback (most recent call last): |
| 64 | ... |
| 65 | ValueError: Barcode 'dwefgiweuf' has alphabetic characters. |
| 66 | """ |
| 67 | if str(barcode).isalpha(): |
| 68 | msg = f"Barcode '{barcode}' has alphabetic characters." |
| 69 | raise ValueError(msg) |
| 70 | elif int(barcode) < 0: |
| 71 | raise ValueError("The entered barcode has a negative value. Try again.") |
| 72 | else: |
| 73 | return int(barcode) |
| 74 | |
| 75 | |
| 76 | if __name__ == "__main__": |