You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's write a function `credit_card_validator` which returns whether a string containing a credit card number is valid as a boolean. The steps are as follows:
5
+
6
+
1. Convert the input string into a list of ints
7
+
2. Slice off the last digit. That is the **check digit**.
8
+
3. Reverse the digits.
9
+
4. Double every other element in the reversed list (starting with the first number in the list).
10
+
5. Subtract nine from numbers over nine.
11
+
6. Sum all values.
12
+
7. Take the second digit of that sum.
13
+
8. If that matches the check digit, the whole card number is valid.
14
+
15
+
Here is a valid credit card number to test with: 4556737586899855
0 commit comments