1

I am currently working on a project where we have to check password strength and generate a strong password, but In the task of making a way for the program to exit I've hit a block, and am unable to find ways to progress. Ive tried break and sys.exit() but neither seem to work. I would like to, when they enter [3] then ['yes'], for the program to end, but it just returns to the first question. I have also attempted the while = True: , but that had even less success.

count = 0
while (count < 1):

    while True:
        choice = input ("Do you want to: 1) Check a password 2) Generate a Password, or 3) Quit? . [1/2/3]? : ")
        if choice in ['1', '2', '3']:
            break
    if choice == "1":
        while True:
            checkyes = input ("you want to check a password, correct? [yes/no]")
            if checkyes in ['yes', 'no']:
               break
    elif choice == "2":
        while True:
            genyes = input ("you want to generate a password, correct? [yes/no]")
            if genyes in ['yes', 'no']:
                break
    else:
        while True:
            quityes = input ("you want to quit, correct? [yes/no]")
            if quityes in ['yes', 'no']:
                break
                if choice == "yes":
                    count = count + 1
                else:
                    pass
1
  • 2
    Your break is before count = count + 1 - that's the problem. Commented Apr 22, 2020 at 13:02

3 Answers 3

1

You are checking the wrong variable for the exit condition. You need to check with quityes:

count = 0
while (count < 1):

    while True:
        choice = input ("Do you want to: 1) Check a password 2) Generate a Password, or 3) Quit? . [1/2/3]? : ")
        if choice in ['1', '2', '3']:
            break
    if choice == "1":
        while True:
            checkyes = input ("you want to check a password, correct? [yes/no]")
            if checkyes in ['yes', 'no']:
               break
    elif choice == "2":
        while True:
            genyes = input ("you want to generate a password, correct? [yes/no]")
            if genyes in ['yes', 'no']:
                break
    else:
        while True:
            quityes = input ("you want to quit, correct? [yes/no]")
            if quityes in ['yes', 'no']:
               if quityes == 'yes'
                    count += 1
                    break
               else:
                   pass

Output:

Do you want to: 1) Check a password 2) Generate a Password, or 3) Quit? . [1/2/3]? : 3
you want to quit, correct? [yes/no]yes

Process finished with exit code 0
Sign up to request clarification or add additional context in comments.

Comments

1

2 problems:

  • the break statement is executed before count in incremented
  • you check choice instead quityes against 'yes'

    if quityes in ['yes', 'no']:       
        if quityes == "yes":
            count = count + 1
        else:
             pass
        break
    

Comments

0

You can try to import sys and replace the break with sys.exit().

Think the reason why the break didnt work is because its breaking out of first loop but not out of the bigger loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.