I am in course that uses Gaddis' Starting Out With Pyton 2nd Edition. There is a problem in the course that asks use to write a program that would capitalize sentences that a user inputs. I have come up with a reasonable solution, but I have two major problems.
The first is that we haven't started using advanced modules like re yet, so I know there is a more elementary way of doing this and second, I can't get it to capitalize proper nouns like Joe and I.
Here is what I am using.
import re def sentCapitalizer(): print('Today you are going to enter a random string.') print('The string can be any number of sentences long.') print('Punctuation is necessary but capitalization is not.') print('Perhaps how you would send a multi-sentence text message.') user_string = input('Enter your string: ') print('Here is the sentence with proper capitalization:') rtn = re.split('([.!?] *)', user_string) print('') print(''.join([each.capitalize() for each in rtn])) sentCapitalizer()
My instructor gave me a hint to utilize the upper() and replace() methods by finding the punctuations, however, I can't seem to figure out how to extract the portions of the strings. (I.e. find ".?!" then search after to determine if the next letter needs to be capitalized.)
Can someone help me with this? I've already turned in the assignment as I did it and was promised credit, but as the assignment isn't due until tommorrow, I'd really like full credit. You don't need to do an entire program, just get me headed in the right direction.