Nov-16-2019, 07:51 PM
I need help with my Python code? I need to test a string of values in the form of '####-####-####', for example; '5000-0000-0000'. I need to test this string values using four rules as stated in my code. However, this string contains the symbol; '-'. I need to remove the two dashes ('-') in the strings. How do I remove the two dashes? Here is my code that I've written so far. Let me know what you think:
def verify(number) : #Rule #1: first digit in credit number = 4 first_digit = '4' if first_digit == number[0]: print('passes rule #1') else: print('violates rule #1') #Rule #2: the fourth digit must be +1 > fifth digit in the credit card number del number[4] del number[9] int(number) for num in number: if num[3]+1 > num[5]: print('passes rule #1 and #2') else: print('passes rule #1, violates rule #20') #Rule #3: the sum of all values in the credit card must be divisible by 4 int(number) #convert number, which is a string of '####-####-####', to an integer sum = 0 skip = False for i in number: if i == number[4] and number[5]: skip = True #skip over the '-' symbol in the credit card value continue else: print('Error: cannot add '-' with integers') sum = sum + i if sum/4 == 0: print('passes rules #1-3') else: print('passes rule #1-2, violates rule #3') #Rule #4: Treat the first two digits as a two-digit number, and the seventh and eighth digits as a two-digit number, and their sum must be 100 first_two_digit = number[0] + number[1] #concatenate the two string values seventh_eighth_digit = number[7] + number[8] int(first_two_digit) #convert concatenated strings to integers int(seventh_eighth_digit) int(number) SumNum = first_two_digit + seventh_eighth_digit for num in number: if SumNum == 100: print('passes rules #1-4') else: print('passes rule #1-3, violates rule #4') return verify input = "5000-0000-0000" output = verify(input) print(output)the error I'm getting is the del number[4] and del number[9], because I can't delete the two dashes in the string list of '####-####-####'