반응형
Quiz>
You should return a given string in reverse order.
Input:
A string.
Output:
A string.
Example:
backward_string('val') == 'lav'
backward_string('') == ''
backward_string('ohho') == 'ohho'
backward_string('123456789') == '987654321'
def backward_string(val: str) -> str:
# your code here
return None
if __name__ == '__main__':
print("Example:")
print(backward_string('val'))
# These "asserts" are used for self-checking and not for an auto-testing
assert backward_string('val') == 'lav'
assert backward_string('') == ''
assert backward_string('ohho') == 'ohho'
assert backward_string('123456789') == '987654321'
print("Coding complete? Click 'Check' to earn cool rewards!")
Solve>
1. 문자열을 거꾸로 뒤집은 후 join으로 연결해서 반환해준다.
def backward_string(val: str):
return ''.join(reversed(val))
Code>
def backward_string(val: str):
return ''.join(reversed(val))
Example>
if __name__ == '__main__':
print("Example:")
print(backward_string('val'))
# These "asserts" are used for self-checking and not for an auto-testing
assert backward_string('val') == 'lav'
assert backward_string('') == ''
assert backward_string('ohho') == 'ohho'
assert backward_string('123456789') == '987654321'
print("Coding complete? Click 'Check' to earn cool rewards!")
Result>
Example:
lav
Coding complete? Click 'Check' to earn cool rewards!
반응형
'Python_Matter > [Check_IO]Elementary' 카테고리의 다른 글
Replace First (0) | 2020.04.11 |
---|---|
Remove All Before (0) | 2020.04.11 |
End Zeros (0) | 2020.04.11 |
Number Length (0) | 2020.04.11 |
Acceptable Password I (0) | 2020.04.11 |