백준

백준 1000번 (A+B)

정호나 2024. 7. 30. 10:10

- input() : 사용자로부터 입력 받기, 입력한 값 문자열로 반환

- int(input()) : 반환된 문자열 정수형을 바꾸기

- a.split() : 여러개의 입력값 받았을 때 공백으로 구분하기

- map() : A,B값 한꺼번에 int함수 적용하기 

 

[map함수 사용 시]
A,B = map(int, input().split())
print = (A+B)

[map함수 사용 안할 때]
A,B = input().split()
a = int(A)
b = int(B)
print(a+b)

 

 

 

- 조건  (0 < A,B <10) 만족시키기

class exp(Exception):
	def _str_(self):
    	return "잘못된 식입니다."
        
def plus():
	a,b = map(int, input().split())
    if not 0 < a 10 or not 0 < b < 10:
    	raise exp()
    print(a+b)
    
try:
 	plus()
except exp as o:
 	print(o)

 

 

 

 

문제

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