Task
The provided code stub reads two integers, a and b, from STDIN.
Add logic to print two lines. The first line should contain the result of integer division, a//b . The second line should contain the result of float division, a/b .
No rounding or formatting is necessary.
Example
Division
if __name__ == '__main__':
a = int(input())
b = int(input())
print(a//b)
print(a/b)
해설
숫자형연산자 기능을 통해 값과 몫을 반환한다.
숫자형 연산자
# 나눗셈 후 값 반환
>>> 7/3
2.3333333333333335
# 나눗셈 후 몫 반환
>>> 7//3
2
# 나눗셈 후 나머지 반환
>>> 7 % 3
1
# 곱셈
>>> 7 * 3
21
# 거듭제곱
>>> 7 ** 3 # 7의 3제곱
343
divmod
>>> divmod(7, 3)
(2, 1)
>>> 몫, 나머지 = divmod(7, 3)
>>> 몫
2
>>> 나머지
1
파이썬 내장함수 divmod는 숫자형연산자 기능과 유사하다
'Develop > hackerrank.com' 카테고리의 다른 글
HackerRank Python Solution / Write a function (0) | 2021.12.31 |
---|---|
HackerRank Python Solution / Loops (0) | 2021.12.30 |
HackerRank Python Solution / Arithmetic Operators (0) | 2021.11.12 |
HackerRank Python Solution / If-Else (0) | 2021.11.11 |
HackerRank Python Solution / "Hello World!" (0) | 2021.11.11 |