Question

python: Part 1: Camel Case Write tests for the following camelCase program. Use your own example...

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

Homework Answers

Answer #1
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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions