python:
Part 1: Camel Case
Write tests for the following camelCase program. Use your own example input strings. If you found bugs, fix them.
Optional: implement a filter to remove special characters from the input string. Write a test for this filter.
s = input("Enter a sentence : ") # Taking input of sentence str_arr = s.split() # splitting the input sentence into words result = "" # initializing result as empty string result += str_arr[0].lower() # Converting first word ( word at index 0 ) of the input sentence into its lowercase for i in str_arr[1:]: #starting iterating from index 1 and onwards result += (i.capitalize()) # Capitalizing rest of the words print("Output : ", result) # printing the required resultant string
def filter(s): punctuations = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' res = "" for x in s: if not(x in punctuations): res += x return res s = input("Enter a sentence : ") # Taking input of sentence s = filter(s) str_arr = s.split() # splitting the input sentence into words result = "" # initializing result as empty string result += str_arr[0].lower() # Converting first word ( word at index 0 ) of the input sentence into its lowercase for i in str_arr[1:]: #starting iterating from index 1 and onwards result += (i.capitalize()) # Capitalizing rest of the words print("Output : ", result) # printing the required resultant string
Get Answers For Free
Most questions answered within 1 hours.