Hi, I have this assignment that I am about to be on the verge of giving up. So this assignment calls for creating a function call "def verify(number)", as show below in the code. So the "verify" function is suppose to verify and "pass" or "fail" any given string list in the format of '####-####-####', based on four rules.
These rules are;
-Rule 1; the first digit in the string must be '4'
-Rule 2; the fourth digit must be one greater than the fifth digit (excluding the dash symbol, '-' in the string list)
-Rule 3; the sum of all digits must be evenly divisible by 4
-Rule 4; the first two digits when converted to a two-digit number, and the seventh and eighth digit is also converted to a two digit number, their sum must be equal to 100.
Now, here is my code that I typed up to meet the requirement to meet these four rules:
These rules are;
-Rule 1; the first digit in the string must be '4'
-Rule 2; the fourth digit must be one greater than the fifth digit (excluding the dash symbol, '-' in the string list)
-Rule 3; the sum of all digits must be evenly divisible by 4
-Rule 4; the first two digits when converted to a two-digit number, and the seventh and eighth digit is also converted to a two digit number, their sum must be equal to 100.
Now, here is my code that I typed up to meet the requirement to meet these four rules:
def verify(number) : #Rule 1 if number[0] == '4': return True else: return False #Rule 2 without_minus = number[0:4]+number[5:9]+number[10:] int(without_minus) for num in without_minus: if num[3]+1 > number[4]: return True else: return False #Rule 3 without_minus = number[0:4]+number[5:9]+number[10:] int(without_minus) SumNum = 0 for i in without_minus: SumNum = SumNum +1 if SumNum/4 == 0: return True else: return False #Rule 4 first_two_digit = number[1] + number[2] seventh_eighth_digit = number[7] + number[8] first_two = int(first_two_digit) seventh_eighth = int(seventh_eighth_digit) sum = first_two + seventh_eighth if sum == 100: return True else: return False return True # modify this line as needed input = "4094-3460-2754" # change this as you test your function output = verify(input) # invoke the method using a test input print(output) # prints the output of the function