x = int(input())
y = int(input())
if x < 0 and y > 0:
print('2')
elif x > 0 and y > 0:
print('1')
elif x < 0 and y < 0:
print('3')
elif x > 0 and y < 0:
print('4')
📍다른 답안1)
a = int(input())
b = int(input())
if a > 0: #x값이 양수
print(1 if b > 0 else 4) #y값이 양수면 1 음수면 4(print문 내에서 if문 선언)
elif a < 0: #x값이 음수
print(2 if b > 0 else 3) #y값이 양수면 2 음수면 3(print문 내에서 if문 선언)
print문 안에 if문을 삽입할 수 있음!
📍다른 답안2)
a,b=open(0)
print('3421'[a>'0'::2][b>'0'])
#문자열 배열 슬라이싱
🍰open(0)
여러 입력을 한 번에 받을 때 open(0).read() 같은 형식사용 가능
0 | stdin |
1 | stdout |
2 | stderr |
print(open(0))
출력해보니 이런 문구가 나온다.
<_io.TextIOWrapper name=0 mode='r' encoding='UTF-8'>
👉mode='r'
mode | 기능 |
---|---|
w | 쓰기모드 |
r | 읽기모드 |
a | 추가모드 |
b | 바이너리모드 |
예문)
f = open("binary_file", "rb") *rb : r(읽기모드)+b(바이너리모드)
✏️문자열 슬라이싱
변수[이상:미만:간격]
🍰'3421'[a>'0'::2] 해석
a>'0' 참이면 1
[참::2]👉 [1::2] 즉, 1 이상 : 2의 간격이므로 '3421' 에서 [1], [3] 의 값인 4, 1
a>'0' 거짓이면 0
[거짓::2] 👉 [0::2] 즉, 0 이상 : 2의 간격이므로 '3421' 에서 [0], [2] 의 값인 3, 2
a>0,b>0 | 1 |
a>0,b<0 | 4 |
a<0,b>0 | 2 |
a<0,b>0 | 3 |