runtime
44 / 500
question 44 Loops & Iteration · medium

Check a barcode's last digit

Shop barcodes (EAN-13) have 13 digits, and the last one is a check digit that catches typing mistakes. Multiply the first 12 digits alternately by 1 and 3 (the digit at position 0 by 1, position 1 by 3, and so on) and add them up. The check digit must equal (10 - total % 10) % 10. Print Valid barcode, Wrong check digit, or Barcode must be 13 digits when the text is not exactly 13 digits.

First linebarcode = "4006381333931". Check runs your program again with other barcodes
PrintsValid barcode
Expected output1 line
  1. 1Valid barcode

Loading your progress…

Check a barcode's last digit — Python practice · Runtime