5.17 LAB: Output words in a sentence that are at least 4 characters long
5.17 LAB: Output words in a sentence that are at least 4 characters long
The starter code reads in user input (assumed to be one or more sentences), and removes the punctuation.
Iterate through the list of words and output the words that are more than 3 characters long.
Ex: If the input is:
Hello, how are you today?the output is:
Helloimport string
userInput = input()
# this creates a mapping which maps each punctuation character to a null string (None)
mapping = str.maketrans('', '', string.punctuation)
# this removes puncutation from the string
userInput = userInput.translate(mapping)
print('User input without punctuation:', userInput)
# split the string into words
words = userInput.split()
print('User input contains the following words: ')
print(words)
I have provided PYTHON CODE along with CODE SCREENSHOT and also provided OUTPUT SCREENSHOT-------------
Step by step
Solved in 4 steps with 2 images