Posts 숫자 비교하기 [Python]
Post
Cancel

숫자 비교하기 [Python]

숫자 비교하기

링크

문제 설명

  • 정수 num1과 num2가 매개변수로 주어집니다. 두 수가 같으면 1 다르면 -1을 retrun하도록 solution 함수를 완성해주세요.

제한 사항

  • 0 ≤ num1 ≤ 10,000
  • 0 ≤ num2 ≤ 10,000

문제 풀이

  • 삼항 연산 if ~ else 구문을 사용하여 풀이
  • [True일때] if a > 5 else [False일때]
1
2
def solution(num1, num2):
    return 1 if num1 == num2 else -1
1
2
3
num1 = 1
num2 = 2
solution(num1, num2)
1
-1
This post is licensed under CC BY 4.0 by the author.