🧸 문제 접근
각각 사분면 마다 x와 y의 음, 양을 적었다.
그 다음 if문으로 각각의 사분면의 조건에 맞으면 그 사분면을 출력해주는 코드를 작성하고자 했다.
🧸 첫 번째 코드(오답)
x = int(input())
y = int(input())
if (x>0, y>0):
print(1)
elif (x<0, y>0):
print (2)
elif (x<0, y<0):
print(3)
else:
print(4)
이 코드가 틀릴리가 없는데.... 하면서 다시 봤다.
알고 봤더니 if 의 조건으로 적은 내용의 ','가 잘못 된 것 이었다.
보통 콤마는 값을 구분하는 데 쓰인다.
하지만 if문 안의 두 조건은 두 조건 모두를 만족해야 하기 때문에
두 조건을 콤마가 아닌 and로 써 주어서 두 조건 모두 만족 했을 때 if문의 조건을 만족하도록 작성해야 한다.
🧸 두 번째 코드(정답)
x = int(input())
y = int(input())
if (x>0 and y>0):
print(1)
elif (x<0 and y>0):
print (2)
elif (x<0 and y<0):
print(3)
else:
print(4)
이렇게 하면 의도한 대로 잘 print 된다!
해당 깃
GitHub - BomEllen/BaekjoonAlgorithm: This is a auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https:/
This is a auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - GitHub - BomEllen/BaekjoonAlgorithm: This is a auto push repositor...
github.com
'🖥️개발 > 🔍Baekjoon' 카테고리의 다른 글
[백준2884_파이썬(Python)] 알람 시계 / 우하하 내가 해냄!! (0) | 2023.04.06 |
---|---|
[백준11382_파이썬(Python)] 꼬마 정민 (0) | 2023.03.23 |
[백준 2588/ 파이썬(python)] 곱셈 (0) | 2023.03.23 |