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!")
'프로그래밍 공부' 카테고리의 다른 글
6.*Python, CheckiO Elementary_Backward String (0) | 2020.10.22 |
---|---|
5. *Python, CheckiO Elementary_End Zeros (0) | 2020.10.22 |
3. Python, CheckiO Elementary_Acceptable Password I (0) | 2020.10.22 |
2. *Python, CheckiO Elementary_First Word (simplified) (0) | 2020.10.22 |
1. Python, CheckiO Elementary_Easy Unpack (0) | 2020.10.22 |
댓글