刚开始学习python并尝试使用循环编写代码来检查唯一字母,如下所示:
def has_unique_letters(x):
count = 0
letters = set(x)
while count < len(x):
if x[count] in letters:
return False
count += 1
return True
Run Code Online (Sandbox Code Playgroud)
但无论我在x中输入什么,它都返回false.代码有什么问题?谢谢!
尝试使用以下代码检查字符串:
def check_password(x):
if has_unique_letters(x) == False:
print "Warning! Please ensure letters are not repeated."
if has_even_vowels(x) == False:
print "Warning! Please ensure password contains an even number of vowels."
if has_special_character(x) == False:
print "Warning! Please ensure password contains at least one of {@, #, *, $}"
if has_divisible_numbers(x) == False:
print "Warning! Please ensure all numbers are divisible by 2 or 3."
print "Sorry, your password does not meet our criteria."
print "Congratulations, your password meets our criteria." …Run Code Online (Sandbox Code Playgroud)