[Python] Input 함수에 범위를 지정해보자!(While 문 활용) 백준 14681번 사분면 문제★VER2.0
2022. 12. 29. 09:08
728x90
반응형
https://www.acmicpc.net/problem/14681
VERSION 2.0
import sys
X = int(sys.stdin.readline())
Y = int(sys.stdin.readline())
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)
VERSION 1.0
format 함수를 활용하여 input함수의 문자열에 받아왔다.
if문을 통해 x축의 범위를 먼저 체크
else문을 통해 x축의 범위가 주어진 문제의 범위안에 들경우 다음 y값 받기
n = 1000
s = -1000
x = None
y = None
while True:
x = int(input(f"x축 값의 범위는 ({s} to {n}): "))
if (x<-1000 or x>1000):
print('x축 값의 범위를 다 시 입력하세요')
else :
while True:
y = int(input(f"y축 값의 범위는 ({s} to {n}): " ))
if (y<-1000 or y>1000):
print('y축 값의 범위를 다 시 입력하세요')
else:
break
break
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")
while문 안에 또 다른 while 문을 부여함으로써 이 범위를 구하는 문제를 구하게 되었다.
728x90
반응형
'Python(백준) > if' 카테고리의 다른 글
[Python] set로 활용해보기(set활용) 백준 2480번 주사위세게 문제 (0) | 2022.09.13 |
---|---|
Python(백준)/if[Python] 백준 2525번 오븐 시계 (0) | 2022.06.24 |
[Python] Input 함수에 범위를 지정해보자!_02번(While 문 활용) 백준 2884번 알람 문제 (0) | 2021.07.24 |