반응형
문장을 받아서 첫 글자는 대문자로 고쳐주고,
마침표가 없으면 마침표를 찍어주는 간단한 문장 교정 문제이다.
텍스트를 받아서 첫글자를 upper로 바꾸고 마침표가 있는 지 검사해서 없으면 찍는 수준의 간단한 방식으로 풀었다.
def correct_sentence(text): a = text[0].upper() text = text[1:] text = a + text if text[-1] != '.': text = text + '.' return text 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." assert correct_sentence("welcome to New York") == "Welcome to New York." print("Coding complete? Click 'Check' to earn cool rewards!")
당연히 정답...
특이한 답은 뭐가 있나 해서봤더니...
딱히 특이할게 없다보니 이정도다..
def correct_sentence(text: str) -> str: first = text[0].upper() middle = text[1:] last = (text[-1]!='.') * '.' return f'{first}{middle}{last}'
곤충인가...
반응형
'게임 프로그래밍 > Python' 카테고리의 다른 글
Jupyter notebook 기본 브라우져 바꾸기 (4) | 2019.01.31 |
---|---|
아나콘다와 파이참 연결 (0) | 2019.01.13 |
CheckIO-First Word (0) | 2018.08.17 |
CheckIO(python) - Say Hi 문제 (0) | 2018.07.30 |
CheckIO(python)-Fizz Buzz 문제 (0) | 2018.07.30 |