PYTHON 홀수짝수

짝수인지 홀수인지 판단해주는 is_evenly_divisible 함수를 쓰세요.

is_evenly_divisiblenumber(수)를 파라미터로 받습니다. 짝수인 경우에는, 즉 number가 2로 나누어 떨어질 경우에는 True를 리턴해줍니다. 홀수인 경우에는, 즉 number가 2로 나누어 떨어지지 않을 경우에는 False를 리턴해줍니다. 함수 안에는 print문을 사용하면 안 되고, return문을 사용하여야 합니다.

1
2
3
4
5
6
def is_evenly_divisible(number):
# 코드를 작성하세요

print(is_evenly_divisible(3))
print(is_evenly_divisible(7))
print(is_evenly_divisible(8))
1
2
3
False
False
True

개인 풀이

1
2
3
4
5
6
7
def is_evenly_divisible(number):
# 코드를 작성하세요
return number%2==0

print(is_evenly_divisible(3))
print(is_evenly_divisible(7))
print(is_evenly_divisible(8))

REFERENCE
코드잇 온라인 강의 프로그래밍 기초

  • © 2020-2025 404 Not Found
  • Powered by Hexo Theme Ayer