Friday, 15 August 2014

While loop issues in Python -



While loop issues in Python -

i'm trying write little python programme utilize in secondary schools teach ciphers.

it's part of ongoing project have do.

however on while loops have if status within them , if status isn't met first time infinitely loops until break.

while esc == false: if guess != cipher: print("error: wrong cipher:" + decrypt(guess, enc)) pass else: esc = true print("correct cipher! decryption successful:" + decrypt(guess, enc))

the cipher here 12 , if input carries on normal, other input gives error message , loops out forever.

i'm c#/c++ background , know python needs in line tab characters , white space , i've checked few times i'm @ loss now.

additional code:

this works fine , it's done same way

while esc == false: if checkpassword(pw) == true: print("authorisation successful.") esc = true else: pw = input("password = : ")

additional places same problem happens:

while esc == false: if attempts < 1: esc = true gameover() elif x == "users": print("users unavailable.") attempts = removeattempt(attempts) pass

i'm not sure else expecting happen. if guess wrong 1 time while loop, going incorrect, because never inquire user guess. note in 1 work, else clause has input new password: don't in either of non-working examples.

(also think might confused pass does: it's no-op, ie nil @ all, , useful syntactically need statement don't want anything. that's not case in either of places utilize it, should remove it. unless perhaps meant break instead, break out of loop?)

python loops while-loop

No comments:

Post a Comment