A program is asked to execute a text that is given as a multi-line string, and then returns statistics on the frequency of characters and word usage in the text based on the following specification. a) Create the auxiliary function capitalize_keep_only_en_chars (word) which accepts a word at the input and returns it in capital letters after ignoring characters other than the English alphabet (punctuation, etc.). For example, to enter "one--" return the word "ONE".
# Python3 program to put spaces between words
# starting with capital letters.
# Function to amend the sentence
def amendSentence(string):
string = list(string)
# Traverse the string
for i in range(len(string)):
# Convert to lowercase if its
# an uppercase character
if string[i] >= 'A' and string[i] <= 'Z':
string[i] = chr(ord(string[i]) + 32)
# Print space before it
# if its an uppercase character
if i != 0:
print(" ", end = "")
# Print the character
print(string[i], end = "")
# if lowercase character
# then just print
else:
print(string[i], end = "")
# Driver Code
if __name__ == "__main__":
string = "BruceWayneIsBatman"
amendSentence(string)
Comments
Leave a comment