STUDY/Algorithm

[프로그래머스] LEVEL1 가운데글자 가져오기,python3

sinawi95 2019. 10. 15. 11:42
728x90

def solution(s):
    answer = ''
    len_s=len(s)
    if len_s%2: # odd
        len_s=int((len_s+1)/2)
        answer=s[len_s-1]
    else:       # even
        len_s=int(len_s/2)
        answer=s[len_s-1:len_s+1]
        
    return answer