0

I need my program to take an input like: "hello there. my name is Bob" and the output to be "Hello there. My name is Bob". Currently it will convert the first letters to uppercase but then also change all others to lower case

def CapitalizeSentence(sentenceInput):
 
    periodIndexNumber = sentenceInput.find(". ")

    print(sentenceInput[0:(periodIndexNumber) + 1].capitalize() + " " + sentenceInput[(periodIndexNumber) + 2:].capitalize() )


sentenceInput = input("Enter sentences to be modified: ")
CapitalizeSentence(sentenceInput)
  • @sK500 that capitalizes all words — they just want the first word in the sentence. See the example they posted. – Mark Jun 14 '22 at 21:32
  • Then `'.'.join(ss.capitalize() for ss in s.split('.'))` will do –  Jun 14 '22 at 21:41
  • 1
    No, it won't @sK500. That's pretty much what they are doing. It makes `Bob` lowercase (and misses the space). – Mark Jun 14 '22 at 21:42
  • 1
    Then what they are asking for is impossible. There is no way to determine whether a word is a name or not, so this is the best possible solution. –  Jun 14 '22 at 21:45
  • LOL All they want to do is make the first letter of a sentence upper case. How can that be impossible?!? They don't need to determine anything about `Bob` unless it's the first word, in which case making it uppercase is fine. @ilynch see the linked dupe — it has a regex solution that is how most people would handle this if you are not worried about other uses of `'.'` like `'Dr. Spock'`. – Mark Jun 14 '22 at 21:52

0 Answers0