![]() You have to provide the numbers within 15 seconds. Upon clicking the link presented in the description of the puzzle, you will be taken to a page asking for valid numbers for Visa, Master Card, and American Express credit cards.You will have to do this in fifteen seconds or less so you have to prepare your “fast hands” game. You just need to provide three valid credit card numbers to the form presented in the page referred to by the description of the puzzle. This is a pretty straightforward challenge. # You can test this code at: and see how it works.This is the last challenge that I was able to answer in the CTF event. Print(IsDivideByTen(DivideByTen(checkFormat(check(CardNumber()))))) # Output final result If SumNumber = 0 and check = True: # <- Fixed code SumNumber = SumCardNumDigits() % 10 # We do this by using the returned value of function SumCardNumDigits()Ĭheck = checkFormat(SplitCardNum) # Finally we check if the sum of digits of credit card number is divisible by 10 If SplitCardNum = True: # If conditions from function check(S) are met, we divide the sum of digits Ncard = card # Using global variable 'card' from function CardNumber()įor i in Ncard: # Summing up all digits in string 'Ncard', if i position in a string is empty space " " # So the returned value from previous function is a list ![]() If SplitCardNum = * 4: # Checking if all above conditions are met in function check(S) SplitCardNum.insert(i, True) # We add to a list a True value at position iĭel SplitCardNum # We delete items at position i + 1 If len(SplitCardNum) = 4 and SplitCardNum.isdigit(): SplitCardNum = CardNumber.split() # Split credit card number into a list, so we get įor i in range(0, len(SplitCardNum)): # Checking if each item in list has length of four strings and each item is Global card # Making variable global for function SumCardNumDigits() see belowĬard = input() # Credit card number is entered For some reason code does not work on Computer Science Circles website, but it works in P圜harm program. Here is my approach, it is a bit longer code but I like using defining functions. if sum(L) % 10 != 0: # % calculates the remainder, which should be 0 L = map(int, S) # makes S into a sequence of integers in one step Put that all together and you get: > def check(S): If sum(L) % 10 != 0: # % calculates the remainder, which should be 0Īnd don't forget to return True if all those tests have passed: return True Last, you want first collect all the digits, and check if there is a remainder: L = map(int, S) # makes S into a sequence of integers in one step What if I had given you 19 spaces: S = S.replace(" ", '') Next, you replace the spaces, but don't check the length again. Moreover, you should return False if any of those 4 conditions is true, not if they are all true at the same time: if len(S) != 19 or S != ' ' or S != ' ' or S != ' ': You are not testing for spaces, only for empty strings, which you'll never find when using straight indices on a python string. ![]() If sum(L)//10 != 0: # checking to see if the sum of the list is divisible by 10 I = int(i) # Making a list out of the string and converting each character to an integer so that it the list can be summed ![]() Return False # checking that the string has only numbers S = S.replace(" ",'') # Taking away spaces in the string Return False # checking if the format is correct Is there a structural issue in my code, or am I using a method incorrectly? def check(S): I think my logic is correct but don't quite understand why it is giving me the wrong value. The following shows what I have come up with. ForĮxample, if S is the string "9384 3495 3297 0123" then although theįormat is correct, the digit sum is 72 so you should return False. Procedure should return True, else it should return False. The digits is divisible by 10 (a "checksum" method), then the If the string does not follow the format "#" whereĮach # is a digit, then it should return False. The function check(S) should take a string S as input. To write a function which checks if a given credit card number is For a free online Python tutorial I need to: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |