0

How do i get my while statement to stop when the user inserts "nee" & exits the program. At the moment when the users inserts nee it keeps on running the program and asking ("Wilt u dit programme gebruiken ? ja/nee: ") for 3 times. After it has asked me for 3 times the program abruptly stops.

I want the program to run when the users inserts ja and to stop when the user inserts nee.

import time
    import sys

    print ("Check of uw wachtwoord veilig genoeg is in dit programma.")
    time.sleep(1)
    print ("Uw wachtwoord moet tussen minimaal 6 en maximaal 12 karakters
    bestaan")
    print ("U kunt gebruik maken van hoofdletters,getallen en symbolen  
    (@,#,$,%)")


    klein = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    groot = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 
    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
    nummers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
    symbolen= [' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-',
    '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', 
    '{', '|', '}', '~',"'"]


    def ok(passwd,l):
        return any(k in passwd for k in l)  # checkt of een letter in de lijst  
    in het wachtwoord zit.

    while input("Wilt u dit programma gebruiken? ja/nee: ") == "ja" or   input("Wilt u dit programma gebruiken? ja/nee: ") == "JA" or input("Wilt u dit programma gebruiken? ja/nee: ") == "Ja":
    ww = input("Voer uw wachtwoord in: ")
    if len(ww) < 6:
        print ("uw wachtwoord is te kort, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
    elif len(ww) > 12:
        print ("uw wachtwoord is te lang, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
    elif len(ww) >= 6 and len(ww)<= 12:
        sww = set(ww)           # set is een onorganiseerde verzameling dat betekent dat het niet op order is bijv. SaUj%2F3 = Oonorganiseerd        
        if all(ok(sww,l) for l in [klein,groot,nummers,symbolen]):
            print ("uw wachtwoord is Zeer sterk")
        elif all(ok(sww,l) for l in [klein,groot,nummers]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [klein,groot,symbolen]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [groot,nummers,symbolen]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [nummers,symbolen,klein]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [nummers,symbolen]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [groot,nummers]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [groot,symbolen]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein,groot]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein,nummers]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein,symbolen]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein]):
            print ("uw wachtwoord is Zwak")
        elif all(ok(sww,l) for l in [symbolen]):
            print ("uw wachtwoord is Zwak")
        elif all(ok(sww,l) for l in [nummers]):
            print ("uw wachtwoord is Zwak")
        elif all(ok(sww,l) for l in [groot]):
            print ("uw wachtwoord is Zwak")
cyberlobe
  • 1,783
  • 1
  • 18
  • 30

2 Answers2

0

It's because you are asking for it three times. When the first condition (== "ja") is wrong it goes on to the next condition (== "JA"). In your case it would then ask a second time for your input. Try doing it with a while true loop:

while True:
    inp = raw_input("Wilt u dit programma gebruiken? ja/nee: ")
    if inp == "nee":
        break
Community
  • 1
  • 1
diiN__________
  • 7,393
  • 6
  • 42
  • 69
0

I would do it this way, checking for .lower() to capture "ja", "Ja", and "JA":

Also, using getpass.getpass() instead of input() for the actual password prevents "local echo on screen" ... so nobody can look over your shoulder when using this.

import time
import sys
import getpass

KLEIN = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
GROOT = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
NUMMERS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
SYMBOLEN = [' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]


def printinstruction():
    print("Check of uw wachtwoord veilig genoeg is in dit programma.")
    time.sleep(1)
    print("Uw wachtwoord moet tussen minimaal 6 en maximaal 12 karakters bestaan")
    print("U kunt gebruik maken van hoofdletters,getallen en SYMBOLEN  (@,#,$,%)")

def ok(passwd, l):
    return any(k in passwd for k in l)  # checkt of een letter in de lijst  in het wachtwoord zit.

def checkww(ww):
    if len(ww) < 6:
        print ("uw wachtwoord is te kort, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
    elif len(ww) > 12:
        print ("uw wachtwoord is te lang, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
    elif len(ww) >= 6 and len(ww) <= 12:
        sww = set(ww)           # set is een onorganiseerde verzameling dat betekent dat het niet op order is bijv. SaUj%2F3 = Oonorganiseerd        
        if all(ok(sww, l) for l in [KLEIN, GROOT, NUMMERS, SYMBOLEN]):
            print("uw wachtwoord is Zeer sterk")
        elif all(ok(sww, l) for l in [KLEIN, GROOT, NUMMERS]):
            print("uw wachtwoord is Sterk")
        elif all(ok(sww, l) for l in [KLEIN, GROOT, SYMBOLEN]):
            print("uw wachtwoord is Sterk")
        elif all(ok(sww, l) for l in [GROOT, NUMMERS, SYMBOLEN]):
            print("uw wachtwoord is Sterk")
        elif all(ok(sww, l) for l in [NUMMERS, SYMBOLEN, KLEIN]):
            print("uw wachtwoord is Sterk")
        elif all(ok(sww, l) for l in [NUMMERS, SYMBOLEN]):
            print("uw wachtwoord is Medium")
        elif all(ok(sww, l) for l in [GROOT, NUMMERS]):
            print("uw wachtwoord is Medium")
        elif all(ok(sww, l) for l in [GROOT, SYMBOLEN]):
            print("uw wachtwoord is Medium")
        elif all(ok(sww, l) for l in [KLEIN ,GROOT]):
            print("uw wachtwoord is Medium")
        elif all(ok(sww, l) for l in [KLEIN, NUMMERS]):
            print("uw wachtwoord is Medium")
        elif all(ok(sww, l) for l in [KLEIN, SYMBOLEN]):
            print("uw wachtwoord is Medium")
        elif all(ok(sww, l) for l in [KLEIN]):
            print("uw wachtwoord is Zwak")
        elif all(ok(sww, l) for l in [SYMBOLEN]):
            print("uw wachtwoord is Zwak")
        elif all(ok(sww, l) for l in [NUMMERS]):
            print("uw wachtwoord is Zwak")
        elif all(ok(sww, l) for l in [GROOT]):
            print("uw wachtwoord is Zwak")

def main():
    printinstruction()
    while True:
        gebruik = input("Wilt u dit programma gebruiken? ja/nee: ")
        if gebruik.lower() == 'ja':
            ww = getpass.getpass("Voer uw wachtwoord in: ")
            checkww(ww)
        if gebruik.lower() == 'nee':
            break

if __name__ == '__main__':
    main()

The checkww() function would be quite large and repetitive, this could be shortened, by introducing a global RESPONSE dictionary, and counting a "factor" to determine the correct response.

At the top of your code (same as the other global variables) you can put the dictionary:

RESPONSE = {1: "uw wachtwoord is Zwak", 2: "uw wachtwoord is Medium", 3: "uw wachtwoord is Sterk", 4: "uw wachtwoord is Zeer sterk"}

Then replace the checkww() with this:

def checkww(ww):
    factor = 0
    if len(ww) < 6:
        print ("uw wachtwoord is te kort, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
        return
    elif len(ww) > 12:
        print ("uw wachtwoord is te lang, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
        return    
    sww = set(ww)
    if all(ok(sww, l) for l in [KLEIN]): factor += 1
    if all(ok(sww, l) for l in [GROOT]): factor += 1
    if all(ok(sww, l) for l in [NUMMERS]): factor += 1
    if all(ok(sww, l) for l in [SYMBOLEN]): factor += 1
    print(RESPONSE.get(factor, "Ooops - something went wrong"))

HTH, Edwin.

Edwin van Mierlo
  • 2,398
  • 1
  • 10
  • 19