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(3)+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

Make sure all your () match.

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.