Hey all, I'm relatively new to python, just started learning it about a week ago. I've been working on making some small scripts to make learning easier for me. This is a cypher script I've been working on that is based off of the order of letters used on a qwerty keyboard. For instance, 'k' would typed be using the middle finger on the right hand (the sixth finger in sequence), and the second in alphabetic sequence, thus 'k' would be 62 (sixth finger second letter). Then the program adds 80 to the final integer and uses the chr() command to convert it to an ASCII character. I haven't written the decrypt script (hehe, kinda rolls of the tongue) yet, but that should be easy as soon as I get this sorted out:
I'm not having much issue with the logic of it, but my multiple if statements in the for loop keep resulting in a syntax error. Do I have to have a separate for loop for each list, or am I missing something obvious? Any help would be great, thanks.

def querty():
    l1 = ['a', 'q', 'z']
    l2 = ['s', 'w', 'x']
    l3 = ('d', 'e')
    l4 = ['b', 'c', 'f', 'g', 'r', 't', 'v']
    l5 = ['h', 'j', 'm', 'n', 'u', 'y']
    l6 = ['i', 'k']
    l7 = ['l', 'o']
    l8 = ['p']
    print('QWERTY cypher developed and coded by Kyle Hovey')
    print('Please enter either decrypt or encrypt below:')
    ed = int(input('Would you like to encrypt or decrypt a message? '))
    if ed == 'encrypt' or 'Encrypt' or 'ENCRYPT':
        message = input('''Please input the message to be encrypted (in quotes):''')
        message = list(message)
        print("Encoded message:")
        for i in list(message):
            if (i in l1) == True:
                print(chr(int(str(1)+str(l1.index(i)+1)+80), end='')
            if (i in l2) == True:
                print(chr(int(str(2)+str(l2.index(i)+1)+80), end='')
            if (i in l3) == True:
                print(chr(int(str(4)+str(l3.index(i)+1)+80), end='')
            if (i in l4) == True:
                print(chr(int(str(4)+str(l4.index(i)+1)+80), end='')
            if (i in l5) == True:
                print(chr(int(str(5)+str(l5.index(i)+1)+80), end='')
            if (i in l6) == True:
                print(chr(int(str(6)+str(l6.index(i)+1)+80), end='')
            if (i in l7) == True:
                print(chr(int(str(7)+str(l7.index(i)+1)+80), end='')
            if (i in l8) == True:
                print(chr(int(str(8)+str(l8.index(i)+1)+80), end='')

--------------------------------------------------------------------------------------

And here's the traceback error:

Traceback (most recent call last):
File "<pyshell#79>", line 1, in <module>
main()
File "/Users/Speleo/Documents/Speleo's Stuff/PYTHON/QUERTY.py", line 23, in main
print(chr(str(4)+str(l4.index(i)+1)+80), end='')
TypeError: Can't convert 'int' object to str implicitly

Are you sure you have run this program!! Just looking at the program I can point out at least 3 mistakes.

Starting with line 12, entering 'encrypt' or 'decrypt' will raise NameError, unless im mistaken. Putting it in quotes will be of no avail, for that will end up raising ValueError or something - you are trying to convert a non numeric string to int!!

Then in line 13 you compare int and string!! How do you expect this to work?

Also in lines 19, 21, 23, 25, 27, 29,and 31 you have not closed all the parenthesis.

Do what you may, but your program wont run beyond line 13!!
Please write down the algorithm properly then try the coding....

Are you using Python 2.x or Python 3.X as one uses raw_input and the other uses input?

# int converts input to an integer so delete it
ed = int(input('Would you like to encrypt or decrypt a message? '))
#
if ed == 'encrypt' or 'Encrypt' or 'ENCRYPT':
# should be
if ed in ['encrypt', 'Encrypt',r 'ENCRYPT']:
# or even better
if ed.lower() == 'encrypt':
#
#
# also
message = list(message)
print("Encoded message:")
# message is already a list
for i in list(message):

Info on keyboard input http://greenteapress.com/thinkpython/html/book006.html#toc61

Indeed what has been said don't convert ed to an integer when you are trying to compare it to a string. Try something like this instead.

ed = raw_input("enter stuff: ")
#instead of using lots of "or's" convert it to upper or lower case letters
ed = ed.lower()
if ed == "encrypt":
  #do this stuff and as already pointed out strings are lists already
  message = "this is my message"
  for character in message:
    #preform actions on the letters in message
    #as far as your sytax error i'm not sure what you are trying to accomplish
    #but if you are doin a comparison from what the character is to what should
    #be printed out from the other list try something like
    if char == "t":
      print l1[1]
    #it's already a string so why are you converting it to an int and then back?
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.