解决下面这样修复后的代码,以帮助任何人,如果他们遇到了这个见面...... 原来的问题 - 只有输入以外的整数过滤掉,而不是整数的范围1-10之外。条件仅在第一次迭代
lc = "abcdefghijklmnopqrstuvwxyz" #string for lc
print("------------------------------------------------------------------------------------------------------------------------------------------------------")
while True:
try:
passlen = int(input("How many lower case characters would you like in the password? (min 1, max 10) "))
if 1<= passlen<=10:
a = "".join(random.sample(lc,passlen))
print("")
counter = counter + (passlen)
left = 10 - counter
nleft = 16 - counter
if counter < 10:
print("You have used", counter, "characters. You need a minimum of", left, "characters and a maxium of", nleft, "characters to create a password of between 10 and 16 charcters.")
print("")
elif counter > 16:
print("You have used", counter, "charcters, more than the allowed maximum of 16 characters. Please follow the rest of the steps and retry when prompted.")
else:
print("You have used", counter, "characters, so have met the minimum amount of characters. You have a maximum of", nleft, "characters remaining to create a password with maximum 16 characters.")
print("")
break
else:
print("Input must be an integer between 1 and 10, please try again.")
except ValueError:
print("Input type must be an integer.")
完全不清楚这段代码应该做什么,再加上问题本身并不明显。 – tadman
您能否提供您的问题[mcve]? –
作为一个风格问题,“互动”这样的节目在20世纪80年代去世。编写一个命令行工具要比'sys.argv'参数好得多,比如你会有一个程序'python passgen.py 20',它会产生一个20个字符的密码或者如果参数产生错误被省略或超出范围。 – tadman