I have to validate that the string is either 4 or 6 digits. The string cannot contain any characters, only integers. Return true if it meets the condition else false.
I tried to create a list with acceptable digits and loop through the string and compare. If any part of the string is not in the acceptable list I will exit the loop and return false. If the running total is equal to 4 or 6 then it should be true. python code:
def validate(n):
count = 0
valid_list = list(range(10))
for digit in pin:
if digit not in valid_list:
return False
count += 1
I'm not sure why something like 1234 is being returned as False.