Prompt: Implement a function that determines whether or not a card number is valid, according to some simple algorithms. Assume that the credit card number is a string consisting of 14 characters and is in the format ####-####-####, including the dashes, where ‘#’ represents a digit between 0-9, so that there are 12 digits overall.
Objective: Implement a function called “verify” that takes a single parameter called “number” and then checks the following rules:
- The first digit must be a 4.
- The fourth digit must be one greater than the fifth digit; keep in mind that these are separated by a dash since the format is ####-####-####.
- The sum of all digits must be evenly divisible by 4.
- If you treat the first two digits as a two-digit number, and the seventh and eighth digits as a two-digit number, their sum must be 100.
If conditions are not met return "rule#X" depending on which rule was failed.
My Progress:
def verify(number):
if len(number) != 14:
return False
if number[0] != 4:
print("rule#1")
if number[5] + 1 != number[3]:
print("rule#2")
if sum(number) != int:
print("rule#3")
if number[0,1] + number[6,7] != 100
print("rule#4")
return True #
input = "5000-0000-0000"
output = verify(input)
print(output)
I think I'm having difficulties with the 3rd and fourth condition but not sure what to do / how to approach it.