728x90
반응형

https://www.acmicpc.net/problem/14681

 

14681번: 사분면 고르기

점 (x, y)의 사분면 번호(1, 2, 3, 4 중 하나)를 출력한다.

www.acmicpc.net

문제 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")

 

Terminal

while문 안에 또 다른 while 문을 부여함으로써 이 범위를 구하는 문제를 구하게 되었다.

728x90
반응형

+ Recent posts