Everything under if statement por que?


#1

Just wondering if it is necessary for the new word codes and commands to all be under the if statement. I saw the pyg and original variable were not and just thought what the difference would be??


#2
if original.length > 0 and original.isalpha():
    # all code here
else
    print "empty:

pyg is a declared variable that remains constant so it is written above everything.


#3

Well, if you move the oringinal variable inside the if statement, you would never be able to satisfy the if as there would be no user input.

As for pyg, it does not matter.

When it comes to the new_word bits, you would want them under the if as it should only happen IF the if is satisfied. If you put the new_word bits outside, I’m guessing before, then you could end up with errors depending on where you placed it. If you place it after all the code, including the else, but outside of the else, then you again could end up with errors. This is because the if the new_word bits are inside of is checking to make sure the original word is valid. If it is not valid we don’t work on it as it could cause errors.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.