Home > Back-end >  Manipulating strings using translate() and lower() in python
Manipulating strings using translate() and lower() in python

Time:12-13

I want to write a program to prompt any statement with punctuation characters, print the statement after removing all the punctuation characters in lower case by separating individual words. Using translate() and lower()

I actually have issues starting. I'm not sure of how to start.

CodePudding user response:

It's a good start:

user_input = input("Enter a statement: ")

#Remove punctuation characters
no_punct = ""
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
for char in user_input:
   if char not in punctuations:
       no_punct = no_punct   char

#Convert to lowercase
result = no_punct.lower()

#Split words
words = result.split()

#Print words
print("Words after removing punctuation characters:")
for word in words:
    print(word)

CodePudding user response:

Code:-

import string
user_input=input("Enter some feedback what you want:\n")
after_punctuation_removal=user_input.translate(str.maketrans('', '', string.punctuation))
#print(after_punctuation_removal)  #see the punctuation removed by printing
convert_lower_case=after_punctuation_removal.lower()
print(convert_lower_case) #Final output

Output:-

Enter some feedback what you want:
I want to write a program!! to prompt any statement with punctuation characters, print the statement after removing all the punctuation characters in lower case by separating individual words. Using translate() and lower() function's
i want to write a program to prompt any statement with punctuation characters print the statement after removing all the punctuation characters in lower case by separating individual words using translate and lower functions
  • Related