I tried to make a leet speak converter, but it outputs characters that I don't even tell it to..

This is what I mean:

(Test run)
Enter something to convert to L337 5P34K: Hi, how are you?
L337 5P34K equivilent: hi,@H0w 4R3 Y0u?

I don't know why it's got the '@' there.

This is the code:

#L33TSP34K Converter.

import random as rnd

def toUpper(string):
    string_upper = ""
    for char in string :
        if  ord(char) < 97 :
            string_upper += char
        elif ord(char) >= 97 :
            string_upper += chr(ord(char) - 32)
    return string_upper

def toLower(string):
    string_lower = ""
    for char in string :
        if ord(char) > 97 :
            string_lower += char
        elif ord(char) <= 97:
            string_lower += chr(ord(char) + 32 )
    return string_lower

def convertToLeetSpeak(src):
    string = src
    for c in src:
        if c == 'e' or c == 'E':
            string += '3'
        elif c == 'a' or c == 'A':
            string += '4'
        elif c == 't' or c == 'T':
            string += '7'
        elif c == 's' or c == 'S':
            string += '5'
        elif c == 'o' or c == 'O':
            string += '0'
        else:
            i = rnd.randrange(1,3)
            if i == 1:
                string += toUpper(c)
            elif i == 2:
                string += toLower(c)
    return string

def main():
    choice = raw_input("Enter something to convert to L337 5P34K: ")
    choice = convertToLeetSpeak(choice).replace(choice, '')
    print 'L337 5P34K equivilent:',choice

if __name__ == '__main__':
    main()

I think it is because you have to be leet to run that code :). J/K...

while count < 256:
	print(chr(count), count)
	count += 1

If you run that then look at line 10 of your script you will see where it came from.

This article has been dead for over six months. Start a new discussion instead.