![]() If our numbers are in a list, we can use the reverse method. We can therefore use the result in a for loop, for example. Reversed will give us back a lazy type (like range), so we can't directly print it however, it is iterable. When you need to get to the step where you reverse the numbers you could use the reversed function, which will accept any sequence type: language = "Python" Remember you can check the model solution if you get stuck!ģ) Once the validation is complete, the program should inform the user whether or not the card number is valid by printing a string to the console. As you go through each digit, you must find a way to determine whether a digit is in an odd or an even position. You should implement this algorithm yourself.Īfter removing the checking digit and reversing the card number, you'll need a for loop to go over the credit card numbers. You may want to turn the user's input into a list of numbers, as that will make it easier to work with.Ģ) The program should validate that card number using the Luhn algorithm described above. If you want to challenge yourself, you should try to be more versatile with regards to the format that you accept card numbers in. However, you should be able to accept a card number with spaces at the start or end of the string. there won't be any spaces between the numbers). For this project, you can assume that the number will be entered as a single string of characters (i.e. The program you write for this project should do the following:ġ) It should be able to accept a card number from the user. 80 is divisible by 10, so the card number is valid. If we perform this series if additions, we get 80. Now we sum these digits and add the checking digit: 7 + 2 + 5 + 5 + 8 + 5 + 2 + 1 + 8 + 0 + 7 + 3 + 9 + 8 + 1 + 9 The number we're going to use is 5893804115457289, which is a valid Maestro card number, but not one which is in use. Let's look at this step by step for a valid number so we can see this in action. If it's not, the card number is not valid. If the result is divisible by 10, the number is a valid card number.Add together all of the results and add the checking digit.If any of the results are greater than 9, subtract 9 from those numbers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |