Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Fool Proof solution in Clear category for Correct Sentence by Tinus_Trotyl
def correct_sentence(text: str) -> str:
return text[:1].upper() + text[1:] + bool(text and text[-1:] != ".") * "."
if __name__ == '__main__':
print("Example:")
print(correct_sentence("greetings, friends"))
# These "asserts" are used for self-checking and not for an auto-testing
assert correct_sentence("greetings, friends") == "Greetings, friends."
assert correct_sentence("Greetings, friends") == "Greetings, friends."
assert correct_sentence("Greetings, friends.") == "Greetings, friends."
assert correct_sentence("hi") == "Hi."
# These extra "asserts" are for cheching some edge cases I have imposed myself on
assert correct_sentence("x") == "X."
assert correct_sentence("hi Hank") == "Hi Hank."
assert correct_sentence("ONLY CAPITALS") == "ONLY CAPITALS."
assert correct_sentence(
"""returns a corrected sentence which starts with a capital letter
and ends with a dot""" ) == (
"""Returns a corrected sentence which starts with a capital letter
and ends with a dot.""" )
assert correct_sentence("split \
sentence") == \
"Split \
sentence."
# this one is not mandatory (the empty string or single dot) but I think it's nice if it can de handled .
assert correct_sentence("") == ""
assert correct_sentence(".") == "."
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 26, 2017