Lab Task 10
Lab Task 10
● Objective:
To implement a credit card number validation system using Luhn's Algorithm and
determine whether a credit card number is valid or invalid.
1. Double every second digit from right to left. If the result is a two-digit number, add
the two digits together.
1
2. Add all the single-digit results from step 1.
3. Add the digits in the odd positions (from right to left).
4. Sum the results from steps 2 and 3.
5. If the total is divisible by 10, the card number is valid; otherwise, it is invalid.
● Python Implementation:
# Return this number if it is a single digit, otherwise return the sum of the two digits
def getDigit(number):
return number if number < 10 else (number // 10 + number % 10)
2
return int(str(number)[:k])
main()
● Flowchart:
● Conclusion:
3
This lab task successfully demonstrates the implementation of Luhn’s Algorithm to
verify credit card numbers. The validation logic ensures both format correctness and
checksum accuracy for common credit card types.