我正在创建一个随机密码生成器。我想创建一个输入字段,其中密码的长度只能是最小 8 和最大 16。如果用户输入的长度不是允许的长度,它会一直要求用户输入正确的密码长度。我使用 'return' 所以它返回到length = int(input('\nEnter the length of password: '))
,但它在这里不起作用。我可以就如何做到这一点获得建议吗?
#input the length of password
#must be minimun 8 to maximun 16
length = int(input('\nEnter the length of password: '))
#if use enter less than 8 or more than 16
if length < 8 :
print('You password length is too short(must be more than 8 character)')
return;
elif length > 16:
print('You password length is too long(must be less than 17 character)')
return;
else:
print('You password length looks good')