ATM机允许4位或6位密码,而密码只能包含4位或6位数字。 如果函数传递了一个有效的PIN字符串,返回true,否则返回false。

题目描述:

ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits.

If the function is passed a valid PIN string, return true, else return false.

eg:

validate_pin("1234") == True
validate_pin("12345") == False validate_pin("a234") == False


我的解答:
def invalid_pin(pin):
if str(pin).startswith("-") or str(pin).find(".") >= 1:
return False
elif str(pin).isdigit() and len(str(pin)) == 4 or len(str(pin)) == 6:
return True
else:
return False
 

猜你喜欢

转载自www.cnblogs.com/wlj-axia/p/12637789.html