Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- ChatGPT
- 프로그래머스 파이썬
- Docker
- 프로그래머스
- github
- programmers
- 캐치카페
- 코로나19
- hackerrank
- 더현대서울 맛집
- 파이썬
- ubuntu
- 편스토랑
- 금융문자분석경진대회
- 우분투
- Kaggle
- PYTHON
- 백준
- 편스토랑 우승상품
- SW Expert Academy
- Git
- Baekjoon
- AI 경진대회
- gs25
- 데이콘
- dacon
- 맥북
- 자연어처리
- Real or Not? NLP with Disaster Tweets
- leetcode
Archives
- Today
- Total
솜씨좋은장씨
[BaekJoon] 13420번 : 사칙연산 (Python) 본문
728x90
반응형

코딩 1일 1문제! 오늘의 문제는 사칙연산 입니다.
13420번: 사칙연산
사칙연산은 덧셈, 뺄셈, 곱셈, 나눗셈으로 이루어져 있으며, 컴퓨터 프로그램에서 이를 표현하는 기호는 +, -, *, / 와 같다. 아래는 컴퓨터 프로그램에서 표현한 사칙 연산의 예제이다. 3 * 2 = 6 문
www.acmicpc.net
Solution
def arithmetic_operation(mathematical_expression):
is_correct = "wrong answer"
num1, operator, num2, _, result = mathematical_expression.split()
num1, num2, result = int(num1), int(num2), int(result)
if (operator == "*") and (num1 * num2 == result):
is_correct = "correct"
elif (operator == "/") and (num1 / num2 == result):
is_correct = "correct"
elif (operator == "+") and (num1 + num2 == result):
is_correct = "correct"
elif (operator == "-") and (num1 - num2 == result):
is_correct = "correct"
return is_correct
if __name__ == "__main__":
for _ in range(int(input())):
mathematical_expression = input()
print(arithmetic_operation(mathematical_expression))
Solution 풀이
먼저 입력 받은 수식을 공백으로 나눈 뒤
첫번째 세번째 숫자를 두번째 operator를 바탕으로 덧셈, 뺄셈, 곱셈, 나눗셈 한 값이
다섯번째 값과 같다면 "correct"를 그렇지 않다면 "wrong answer"를 출력하도록 합니다.
SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[BaekJoon] 10769번 : 행복한지 슬픈지 (Python) (0) | 2021.07.10 |
---|---|
[BaekJoon] 2870번 : 수학숙제 (Python) (0) | 2021.07.09 |
[BaekJoon] 8595번 : 히든 넘버 (Python) (0) | 2021.07.07 |
[BaekJoon] 18406번 : 럭키 스트레이트 (Python) (0) | 2021.07.06 |
[BaekJoon] 14726번 : 신용카드 판별 (Python) (0) | 2021.07.05 |