Open the context
Choose the project folder and name the files or behavior involved.
Validate a synthetic string of 2 through 64 ASCII digits with the Luhn checksum. Keep leading zeros and test both parity lengths, rejecting spaces and non-ASCII digits without claiming account validity.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def luhn_valid(text):
if type(text) is not str or not 2 <= len(text) <= 64:
raise ValueError("luhn.length")
if any(char < "0" or char > "9" for char in text):
raise ValueError("luhn.alphabet")
total = 0
for index, char in enumerate(reversed(text)):
digit = ord(char) - ord("0")
if index % 2:
digit *= 2
if digit > 9:
digit -= 9
total += digit
return total % 10 == 0The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.