Please help! My programme is outputting random strings, mixing up lower and upper case, and weirdest of all, it refuses to print plainText input as it is when it's not a letter - it insists on modifying it by key, which is hilarious since it doesn't modify textual output correctly by key.

Is there something I have misunderstood about scope in Python? Or is this about unicode? I just can't for the life of me see where the bug is.

The relevant excerpt of my code is below:

// check usage

// get key, modulo by 26

// get plainText

for i in range(len(plainText)):

# if not a letter, just print
if plainText[i].isalpha == False:
    print("{}".format(plainText[i]), end="")

# if uppercase text, wraparound 90
elif plainText[i].isupper:
    cipher = ord(plainText[i]) + key
    if cipher > 90:
        cipher -= 26
    print("{}".format(chr(cipher)), end="")

# if lowercase text, wraparound 122           
elif plainText[i].islower:
    cipher = ord(plainText[i]) + key
    if cipher > 122:
        cipher -= 26
    print("{}".format(chr(cipher)), end="")
  • For example: < Hello, world > prints as KNUUX/#`X[UM – StephanieJosine Mar 6 '17 at 8:26

You should call your functions, by adding parentheses ():

if not plainText[i].isalpha():

elif plainText[i].isupper():

elif plainText[i].islower():

Otherwise you refer to the method, which is always interpreted as true

  • Wow... so simple! Thank you so much, it works perfectly now ^_^ – StephanieJosine Mar 6 '17 at 11:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .