0

Help please (Bug in code) My code passes 5/7 test cases but I can’t see the ones it doesn’t pass. Any help is appreciated

This is for Credit Card Validator on Code coach You need to verify if the given credit card number is valid. For that you need to use the Luhn test. Here is the Luhn formula: 1. Reverse the number. 2. Multiple every second digit by 2. 3. Subtract 9 from all numbers higher than 9. 4. Add all the digits together. 5. Modulo 10 of that sum should be equal to 0. Task: Given a credit card number, validate that it is valid using the Luhn test. Also, all valid cards must have exactly 16 digits. Input Format: A string containing the credit card number you need to verify. Output Format: A string: 'valid' in case the input is a valid credit card number (passes the Luhn test and is 16 digits long), or 'not valid', if it's not. Sample Input: 4091131560563988 Sample Output: valid https://code.sololearn.com/c3tdH96LZ85p/?ref=app

9th Mar 2021, 8:57 PM
Javier
Javier  - avatar
2 ответов
+ 2
You should use Regex . i think they go through that in the course !
9th Mar 2021, 10:23 PM
Med Amine Fh
Med Amine Fh - avatar
+ 1
Start fix the if statments. For now you print out two (contadicting) statments: not valid valid
9th Mar 2021, 10:45 PM
Per Bratthammar
Per Bratthammar - avatar