1

I'm trying to write a small Python program for use in secondary schools to teach about ciphers.

It's all part of an ongoing project they have to do.

However on my while loops I have an if condition inside them and if the condition isn't met the first time it just infinitely loops until I break.

while esc == False:
    if guess != cipher:
        print("ERROR: INCORRECT CIPHER:" + Decrypt(guess, enc))
        pass
    else:
        esc = True
        print("Correct Cipher! Decryption successful:" + Decrypt(guess, enc))

The cipher here is 12 and if that is input it carries on as normal, however any other input just gives the error message and loops out forever.

I'm from a C#/C++ background usually and I know Python needs to be in line with its tab characters and white space and I've checked that a few times but I'm at a loss now.

ADDITIONAL CODE:

This works fine and It's done the same way

while esc == False:
    if CheckPassword(pw) == True:
        print("Authorisation successful.")
        esc = True
    else:
        pw = input("Password =  :  ")

ADDITIONAL PLACES WHERE SAME PROBLEM HAPPENS:

while esc == False:
    if attempts < 1:
        esc = True
        GameOver()
    elif x == "USERS":
        print("USERS UNAVAILABLE.")
        attempts = RemoveAttempt(attempts)
        pass
1
  • Where and what is your question ? Commented Oct 13, 2014 at 12:47

1 Answer 1

5

I'm not sure what else you are expecting to happen. If the guess is incorrect once you get into the while loop, it is going to always be incorrect, because you never ask the user for another guess. Note that in the one that does work, the else clause has an input for a new password: you don't do that in either of your non-working examples.

(Also I think you might be confused about what pass does: it's simply a no-op, ie it does nothing at all, and is only useful where you syntactically need a statement but don't want to do anything. That's not the case in either of the places you use it, so you should remove it. Unless you perhaps meant break instead, to break out of the loop?)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man, I'm trying to learn Python whilst doing this and I got myself all confused. As for the pass you're absolutely right before posting I tried everything even the ridiculous to see if I could get it working and it was meant to be a break I didn't put back in. Thanks for your reply and I'll see if I can get it working.

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.