Q>
For the input of your function, you will be given one sentence. You have to return a corrected version, that starts with a capital letter and ends with a period (dot).
(함수의 입력을 위해, 당신은 한 문장을 받게 될 것입니다. 대문자로 시작하고 마침표 (점)로 끝나는 수정 된 버전을 반환해야합니다.)
Pay attention to the fact that not all of the fixes are necessary. If a sentence already ends with a period (dot), then adding another one will be a mistake.
(모든 수정 사항이 필요한 것은 아니라는 사실에 유의하십시오. 문장이 이미 마침표 (점)로 끝나면 다른 문장을 추가하는 것은 실수입니다.)
Input: A string.
(입력 : 문자열.)
Output: A string.
(출력 : 문자열.)
Example:
1 correct_sentence("greetings, friends") == "Greetings, friends."
2 correct_sentence("Greetings, friends") == "Greetings, friends."
3 correct_sentence("Greetings, friends.") == "Greetings, friends."
Precondition: No leading and trailing spaces, text contains only spaces, a-z A-Z , and .
(사전 조건 : 선행 및 후행 공백 없음, 텍스트에는 공백 만 포함, a-z A-Z 및.)
A>
def correct_sentence(text: str) -> str:
"""
returns a corrected sentence which starts with a capital letter
and ends with a dot.
"""
# your code here
# 문자에 첫글자 대문자 / 끝글자는 . / . 이 있으면 . 제외
# upper : 소문자를 대문자로 변환
text = text[0].upper() + text[1:]
# endswith : 마지막에 있는 글자를 찾는 메소드
if not text.endswith('.'):
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!")
O>
Greetings, friends.
Process finished with exit code 0
S>
'Python_Matter > Solve' 카테고리의 다른 글
Python Learn the basics Quiz 41 (0) | 2019.06.09 |
---|---|
Python Learn the basics Quiz 40 (0) | 2019.06.08 |
Python Learn the basics Quiz 38 (0) | 2019.06.08 |
Python Learn the basics Quiz 37 (0) | 2019.06.07 |
Python Learn the basics Quiz 36 (0) | 2019.06.07 |