944,123 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 660
  • Python RSS
Oct 30th, 2009
0

Problems with a leet speak converter

Expand Post »
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:

python Syntax (Toggle Plain Text)
  1. #L33TSP34K Converter.
  2.  
  3. import random as rnd
  4.  
  5. def toUpper(string):
  6. string_upper = ""
  7. for char in string :
  8. if ord(char) < 97 :
  9. string_upper += char
  10. elif ord(char) >= 97 :
  11. string_upper += chr(ord(char) - 32)
  12. return string_upper
  13.  
  14. def toLower(string):
  15. string_lower = ""
  16. for char in string :
  17. if ord(char) > 97 :
  18. string_lower += char
  19. elif ord(char) <= 97:
  20. string_lower += chr(ord(char) + 32 )
  21. return string_lower
  22.  
  23. def convertToLeetSpeak(src):
  24. string = src
  25. for c in src:
  26. if c == 'e' or c == 'E':
  27. string += '3'
  28. elif c == 'a' or c == 'A':
  29. string += '4'
  30. elif c == 't' or c == 'T':
  31. string += '7'
  32. elif c == 's' or c == 'S':
  33. string += '5'
  34. elif c == 'o' or c == 'O':
  35. string += '0'
  36. else:
  37. i = rnd.randrange(1,3)
  38. if i == 1:
  39. string += toUpper(c)
  40. elif i == 2:
  41. string += toLower(c)
  42. return string
  43.  
  44. def main():
  45. choice = raw_input("Enter something to convert to L337 5P34K: ")
  46. choice = convertToLeetSpeak(choice).replace(choice, '')
  47. print 'L337 5P34K equivilent:',choice
  48.  
  49. if __name__ == '__main__':
  50. main()
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008
Oct 30th, 2009
0
Re: Problems with a leet speak converter
I think it is because you have to be leet to run that code . J/K...
python Syntax (Toggle Plain Text)
  1. while count < 256:
  2. print(chr(count), count)
  3. count += 1
If you run that then look at line 10 of your script you will see where it came from.
Reputation Points: 17
Solved Threads: 9
Junior Poster in Training
willygstyle is offline Offline
60 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: How to integrate vumeter
Next Thread in Python Forum Timeline: Converting Python VERSION 3 scripts to .exe





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC