코딩 테스트/Python

백준, Python) 1단계 입출력과 사칙연산

나무늘보섬 2025. 4. 2. 23:08

2~6

원래 작성한 코드

a,b = input().split()
a= int(a); b=int(b)
if a>0 and b<10 and b!=0:
    print(a/b)

 

 

다른 분들에 비해 시간이 오래 걸려서 찾아보니 

a,b = map(int, input().split())
print(a+b)

-> 이 방식으로 작성하기

 

 

10430번

조건 

if (x>=2 and y>=2 and z>=2) and (x<=1000 and y<=1000 and z<=1000):
 

 

-> 간소화 버전

if all(2 <= v <= 1000 for v in (x, y, z)):

 

근데 조건까지 추가하면 계속 틀렸다고 나와서 조건을 뺏더니 맞았다고 함,,

 

2588번

하드코딩식 

x = int(input())
y = str(input())
print(x*int(y[2]))
print(x*int(y[1]))
print(x*int(y[0]))
print(x*int(y))

 

 

-> 간결하게 표현 다시

x = int(input())
y = str(input())
for num in range(len(y)):
    print(x * int(y[len(y)-num-1]))
print(x*int(y))

 

10171번 아스키 고양이

print("\\    /\\")
print(" )    ( ')")
print("(  /  )")
print(" \(__)|")

백슬래시 유의

 

10171번 개 출력

print("|\_/|")
print("|q p|   /}")
print('( 0 )"""\\')
print('|"^"`    |')
print("||_/=\\\\__|")