如何删除某个结果中的命令:
pass1 = input("What is your password: ")
pass2 = input("Rewrite your password: ")
if len(pass1) > 5:
print ("")
else:
print ("Your password must be at least 5 characters long")
print ("*******************")
print ("Loading...")
print ("*******************")
time.sleep(1)
if pass1 == pass2:
print ("All right, your password is: " + pass1)
else:
print ("Sorry, your passwords don't match")
基本上当我运行它并输入一个不是5个字符长的密码时,它仍会显示我的密码。
我想要做的是当密码长度不超过5个字符时,我希望密码不显示。
if pass1 == pass2:
print ("All right, your password is: " + pass1)
else:
print ("Sorry, your passwords don't match")
答案 0 :(得分:0)
只需移动if
分支内的相关代码:
pass1 = input("What is your password: ")
pass2 = input("Rewrite your password: ")
if len(pass1) > 5:
print ("")
print ("*******************")
print ("Loading...")
print ("*******************")
time.sleep(1)
if pass1 == pass2:
print ("Alright, you're password is: " + pass1)
else:
print ("Sorry, your passwords don't match")
else:
print ("Your password must be at least 5 characters long")
答案 1 :(得分:0)
难道你不能像这样嵌套ifs吗?
if len(pass1) > 5:
if pass1 == pass2:
#...
else:
#...
else:
#...