172k views
1 vote
Write a program that requests a sentence as input and translates it into textese. Assume that there is no punctuation in the sentence. (note: if a word in the sentence is not in the text file, it should appear as itself in the textese translation. )

User Bland
by
8.1k points

1 Answer

2 votes

# Define a dictionary that maps words to their textese equivalents

textese_dict = {

'and': '&',

'you': 'u',

'to': '2',

'for': '4',

'ate': '8',

'be': 'b',

'see': 'c',

'are': 'r',

'why': 'y',

'oh': 'o',

'okay': 'k',

'before': 'b4',

'later': 'l8r',

'great': 'gr8',

'too': '2',

'two': '2',

'four': '4',

'eight': '8'

}

# Get a sentence from the user

sentence = input("Enter a sentence to translate to textese: ")

# Split the sentence into a list of words

words = sentence.split()

# Translate each word into textese, if possible

textese_words = []

for word in words:

textese_word = textese_dict.get(word.lower(), word)

textese_words.append(textese_word)

# Join the textese words into a sentence

textese_sentence = ' '.join(textese_words)

# Print the textese sentence

print("Textese translation:", textese_sentence)


This program defines a dictionary that maps words to their textese equivalents, and then prompts the user to enter a sentence to translate. The sentence is split into a list of words, and each word is translated into textese using the dictionary. If a word is not in the dictionary, it is left as is. Finally, the textese words are joined back together into a sentence and printed to the console.

Note that this program assumes that the input sentence has no punctuation. If there is punctuation in the sentence, it will need to be removed before the program can translate the words into textese.

User Joey Sabey
by
8.1k points