본문 바로가기
프로그래밍 공부

4. Python, CheckiO Elementary_Number Length

by 응_비 2020. 10. 22.

You have a positive integer. Try to find out how many digits it has?

Input: A positive Int

Output: An Int.

Example:

number_length(10) == 2

number_length(0) == 1

1

2

 

-> Solve it

 

def number_length(a: int) -> int:
    return len(str(a))

# len은 자릿수의 개수를 알려주는 함수이다.


if __name__ == '__main__':
    print("Example:")
    print(number_length(10))

    # These "asserts" are used for self-checking and not for an auto-testing
    assert number_length(10) == 2 (두자리수)
    assert number_length(0) == 1 (한자리수)
    assert number_length(4) == 1
    assert number_length(44) == 2
    print("Coding complete? Click 'Check' to earn cool rewards!")

댓글