0

How do I delete a command in a certain result:

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")

basically when I run this and type in a password that is not 5 characters long it still shows what my password is.

What I am trying to do is when a password is not 5 characters long I want it to make that not show up.

if pass1 == pass2:
    print ("All right, your password is: " + pass1)
else:
    print ("Sorry, your passwords don't match")
Lev Levitsky
  • 59,844
  • 20
  • 139
  • 166
rZero3
  • 1,659
  • 1
  • 12
  • 8
  • Possible dupe of http://stackoverflow.com/questions/9202224/getting-command-line-password-input-in-python, use [getpass](http://docs.python.org/2/library/getpass.html#getpass.getpass) – ddelemeny Mar 23 '14 at 14:00
  • Oh wait, misread the question. sorry for that, i'll leave the comment because getpass is an interesting resource to know – ddelemeny Mar 23 '14 at 14:07

2 Answers2

0

Just move the relevant code inside the if branch:

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")
grayshirt
  • 607
  • 4
  • 12
0

Can't you just nest the ifs like so?

if len(pass1) > 5:
    if pass1 == pass2:
        #...
    else:
        #...
else:
    #...
Dunno
  • 3,522
  • 3
  • 26
  • 41