我试图让用户输入密码(在为我的测验创建帐户时)并检查密码是否超过6个字符。如果不是,它将循环返回并要求用户尝试另一个密码。这是我到目前为止所得到的:
def password ():
password = input("enter a password over 6 characters")
count = 0
for letter in password:
count = count + 1
while count < 6:
password = input("password too short try again")
password ()
如果我的密码足够长,我会得到的是:
enter a password over 6 characters longpassword
如果我的密码太短,我得到的是
enter a password over 6 characters lol
password too short try again lol
password too short try again longpassword
password too short try again
第一次看起来并没有计算出角色,我也不知道为什么。
答案 0 :(得分:2)
password = ""
while len(password) < 6:
password = input("....")