Skip to content

RonakReyhani/shecodes-week-5-task-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Week 5 Task 1

Your task is to implement the algorithms to calculate and validate check digits for different kinds of barcodes.

You must calculate and validate the check digit for:

  • Credit Cards

And choose one or more of:

  • ISBN-10 Books
  • ISBN-13 Books
  • GTIN-13 Product Codes

To help you get started:

GTIN-13 check digits are calculated as follows:

  1. Multiply every second digit by 3, and every other digit by 1.
  2. Add up all the multiplied numbers.
  3. You can now get the check digit by working out what number would have to be added to the sum in order to bring it up to a multiple of 10. If the number is already a multiple of 10, the check digit is 0.

ISBN-10 check digits are calculated as follows:

  1. Multiply the first digit in the barcode by 10. Add the result to the sum.
  2. Multiply the second digit in the barcode by 9. Add the result to the sum.
  3. Multiply the third digit in the barcode by 8. Add the result to the sum.
  4. ....
  5. Multiply the last number in the barcode by 1. Add the result to the sum.
  6. Calculate the remainder of the sum when divided by 11.
  7. The check digit is 11 minus the remainder of the result in step 6 when divided by 11. If the check digit is 10, it is replaced with an ‘X’.

Running your program:

If I provide this input:

print(calculate_gtin13_barcode_check_digit('940055061977'))

The output I expect is:

5

If I provide this input:

print(validate_gtin13_barcode_check_digit('9400550619775'))

The output I expect is:

This is a valid gtin13 barcode.

The only thing that should change is the name of the function dependant on the type of barcode (i.e. gtin13, isbn10, isbn13 or credit_card).

Note: obviously your code should handle more test cases than just the two I provided, these are just examples to demonstrate how I expect to be able to call your code).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages