def sentence_maker(phrase): interrogatives = ("how", "what", "why") capitalized = phrase.capitalize() if phrase.startswith(interrogatives): return "{}?".format(capitalized) else: return"{}.".format(capitalized) results = [] while True: user_input = input("Say something: ") if user_input == "\end": break else: results.append(sentence_maker(user_input)) print(" ".join(results))
When the program is run the console will ask for user input in the form of "Say something: "
If the user types in any sentences that start with the keywords "how, what, or why" the program will add a question mark to the end of the sentence.
Otherwise, if the sentence does not start with any of the keywords then it will insert a period at the end of the sentence.
The the variable "capitalized' will capitalize the first letter of each sentence.
The where clause will have the console repeatedly ask for user input until the user types in "\end".
When sentences are typed into the console they will be strung together into one sting and printed after the program has ended.
Here is an example of what the program will do:
Say something: hello
Say something: how are you going today
Say something: That's good
Say something: what are you doing today
Say something: sounds fun
Say something: \end Hello.
How are you going today? That's good. What are you doing today? Sounds fun.
No comments:
Post a Comment