How would you write this program in Python IDLE?

Write a program with a function that accepts a string as an argument and returns (some type of return value) a copy of the string with the first character of each sentence capitalized. For instance, if the argument is "hello. my name is Joe. what is your name?" the function should return a string "Hello. My name is Joe. What is your name?" The program should let the user enter a string and then pass it to the function. The modified string should be displayed.

I need help writing this program! I would greatly appreciate it. This all has to do with strings. Im learning the basics of Python, so just writing this program in basic concepts would be best.

Thank You

Recommended Answers

All 3 Replies

We wait to see your efforts (inside CODE tags) and point you to right direction.

Python has a some string functions that will help, but you need to add your spaces and periods back in. Experiment a little and have fun ...

s = "hello. my name is Joe. what is your name?"

sentence_list = s.split('.')
print(sentence_list)

for sentence in sentence_list:
    sentence = sentence.strip()
    print(sentence.capitalize())

''' my result -->
['hello', ' my name is Joe', ' what is your name?']
Hello
My name is joe
What is your name?
'''

Notice what happened with Joe? Stumbled it myself few times.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.