
Title:
Luhns Algorithm Cont  Software Testing

Description:

Here's a look at what you're going to do in a little bit more detail.

Remember that what you're writing is a random tester

for the credit card transaction processing system.

The core of this random tester is going to be a function called generate,

which is what you're going to implement, so generate is going to take two parameters.

The first one is the prefix, which is going to correspond to the issuer identifier.

And this is a sequence of digits which is given to you, which has to appear at the start

of the credit card number that you generate.

The second parameter is the length. That is to say, an integer parameter that determines the total length

in digits of the credit card number that you're going to generate.

So your job then is to construct your credit card number,

which has the given issuer identifier or prefix, has the required total length,

has completely random integers in the middle here, and has a valid checksum digit

as computed using Luhn's algorithm plus this little procedure for turning the Luhn checksum

into a digit, which makes an overall credit card number's checksum

come out to be 0 and therefore be valid.

So let's just look at the code quick. So what you're writing is a function called generate.

It takes the prefix and the length and so you're code is going to go here.

And so we might call it like this. We might say the prefix is 372542.

This happens to be the prefix for a credit card that I have in my pocket.

and a 15digit credit card number and now you're going to create a valid credit card number

with the required properties.

To do this, you're probably going to want to implement a function called Lahn checksum

which computes the checksum of a number and this axillary function isluhnvalid simply checks

if the Lahn checksum or a given input is 0.

what I'd like you to do is implement that now.

If you get totally stuck and you like kind of a hint, there's something you can do

which is look up Lahn's algorithm on Wikipedia.

The reason that's kind of cheating is because on this Wikipedia page for Luhn's algorithm

they actually will give you a Python code that works.

But don't go there unless you actually want to see the real answer.

Okay. Take a few minutes now, write the code, and what our API will do is use it

to generate a number of credit cards and check if they're valid.

If they're not valid, it will give you some indication on that the problem is.

And if they are valid, then it will tell you what the N and you can move on to the solution.

Before I let you go hack on this, I just want to give you a quick reminder about something

that should save you some trouble so in the discussion I did here about Luhn's algorithm

I assumed that the digits were numbered starting out 1.

For example, #1 here is an oddnumbered digit.

This is digit #2 which is an evennumbered digit, #3 is odd, etc.

Now on the other hand, Python strings are index starting at 0.

That's something you're going to have to watch out for.

Or else you're going to go a little off by 1 error in your code that makes it a pain to debug.