Question

In: Computer Science

python: Write a program that turns a sentence into camel case. The first word is lowercase,...

python:

Write a program that turns a sentence into camel case. The first word is lowercase, the rest of the words have their initial letter capitalized, and all of the words are joined together. For example, with the input "fOnt proCESSOR and ParsER", your program will output "fontProcessorAndParser".

Optional: can you do this with a list comprehension?

Optional extra question: print a warning message if the input will not produce a valid variable name. You don't need to be exhaustive in checking, but test for a few common issues, such as starting with a number, or containing invalid characters such as # or + or ".

Test your program, and comment your code.

Solutions

Expert Solution

Python Code Screenshot with Output :

Python Code :

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:]:               # Now, we'll start iterating from index 1 and onwards
    result += (i.capitalize())             # Capitalizing rest of the words
  
print("Output : " , result)            # printing the required resultant string

Note :    Hi, whenever we paste the code in the answer box, the indentation of the code gets disturbed. And as we know that It is necessary to indent the code in python before running, to avoid any indentation error. So, Before running the code, Please indent the provided code ( as in the above screenshot ). Otherwise, you might get indentation error.


Related Solutions

write a python program that reads a sentence and identifies a word from an existing glossary...
write a python program that reads a sentence and identifies a word from an existing glossary and states the meaning of the word
In PYTHON: Write a function that receives a sentence and returns the last word of that...
In PYTHON: Write a function that receives a sentence and returns the last word of that sentence. You may assume that there is exactly one space between every two words, and that there are no other spaces at the sentence. To make the problem simpler, you may assume that the sentence contains no hyphens, and you may return the word together with punctuation at its end.
Write a function in python that accepts a sentence as the argument and converts each word...
Write a function in python that accepts a sentence as the argument and converts each word to “Pig Latin.” In one version, to convert a word to Pig Latin, you remove the first letter and place that letter at the end of the word. Then you append the string “ay” to the word. Here is an example: English: I SLEPT MOST OF THE NIGHTPIG LATIN: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY. Please, I want the coding indented and then the...
Python Write a function str_slice(s) to slice sentence into single word by their spaces and punctuations...
Python Write a function str_slice(s) to slice sentence into single word by their spaces and punctuations and returns a list. You cannot use split(), join() method for this define function Example: >>>str_slice(‘Hi, I like it!!’) [‘Hi’, ‘, ’, 'I', ‘ ‘, ‘like’, ‘ ‘, ‘it’, ‘!!’]
Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
Write a python program that calculates the average number of words per sentence in the input...
Write a python program that calculates the average number of words per sentence in the input text file. every sentence ends with a period (when, in reality, sentences can end with !, ", ?, etc.) and the average number of sentences per paragraph, where a paragraph is any number of sentences followed by a blank line or by the end of the text.
Python 3 Program Program 4 should first tell users that this is a word analysis software....
Python 3 Program Program 4 should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file. Using...
Write Python code that checks if an existing variable letter is a lowercase vowel. If it...
Write Python code that checks if an existing variable letter is a lowercase vowel. If it is a, e, i, o, or u and print out "Yes, it is a lowercase vowel". If the letter is y, print out "The letter is a consonant". If the letter is anything else, print out "No, the letter is not a vowel". (language python)
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT