본문 바로가기

Programming [Python]/백준 알고리즘 솔루션

#251 백준 파이썬 [13420] 사칙연산

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

 

Solution

eval 함수를 통해서 쉽게 풀이할 수 있다. 또한 =을 기준으로 나누어지므로 split함수를 적절하게 이용하면 쉽게 풀 수 있다.

Python Code

T = int(input())
for _ in range(T):
    prob, answer = map(str, input().split('='))
    
    if eval(prob) == int(answer):
        print("correct")
    else:
        print("wrong answer")