Difference between revisions of "Leet-speak Translator"

From WLCS
Line 21: Line 21:
 
     if ch == "a":
 
     if ch == "a":
 
         return "@"
 
         return "@"
 +
    if ch == "b":
 +
        return "l8"
 +
    # add the rest of your alphabet here
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 28: Line 31:
 
## Inside the loop, translate the current letter (word[x]) by using the '''getLetter(word[x])''' AND add it to '''newWord''' (HINT: use the warmup we did before)
 
## Inside the loop, translate the current letter (word[x]) by using the '''getLetter(word[x])''' AND add it to '''newWord''' (HINT: use the warmup we did before)
 
# After the loop, '''newWord''' should contain a translation of every letter.  Print out '''newWord'''
 
# After the loop, '''newWord''' should contain a translation of every letter.  Print out '''newWord'''
 +
 +
'''Advanced Features:'''
 +
# Update '''getLetter()''' so that it is able to handle spaces and punctuation
 +
# Can you create a reverse translator?

Revision as of 09:15, 14 March 2011

Objectives:

  • You will create a string translator that converts from regular characters to leetspeak characters
  • You will use while loops to traverse (walk-through) a string
  • You will use if-statements to check for particular letters
  • You will use functions to retrieve the corresponding leetspeak characters

References:

Directions:

  1. Open a new python file and name is leetTranslator.py
  2. In a separate textfile, bring up your leet alpha reference card
  3. Define a function named getLetter(ch) that takes one parameter. Inside the definition of getLetter(), you will check to see what letter ch is, and then return the corresponding leet character. See the example code below and complete it with the rest of the alphabet
def getLetter(ch):
    if ch == "a":
        return "@"
    if ch == "b":
        return "l8"
    # add the rest of your alphabet here
  1. After the function definition, prompt the user to enter a word and store it in a variable named word
  2. Initialize a new variable named newWord to an empty string ""
  3. Write a loop that traverses the word string
    1. Inside the loop, translate the current letter (word[x]) by using the getLetter(word[x]) AND add it to newWord (HINT: use the warmup we did before)
  4. After the loop, newWord should contain a translation of every letter. Print out newWord

Advanced Features:

  1. Update getLetter() so that it is able to handle spaces and punctuation
  2. Can you create a reverse translator?