본문 바로가기

언어/Python

[Python] 사칙 연산

 

 

 

 

1. A+B 출력하기 
A, B = map(int,input().split())
print(A+B)

2. A-B 출력하기 
A, B = map(int,input().split())
print(A-B)


3. A*B 출력하기 
A, B = map(int,input().split())
print(A*B)


4. A/B 출력하기 
A, B = map(int,input().split())
print(A/B)

 

 

 

 

 

사칙연산 출력하기

다만, 주의할 점이 파이썬은 나눗셈을 할 때 

A/B 라면 실수의 몫을 출력하기 때문에 A//B를 사용해야 한다.

 

 

조건: 1<= A, B <=10000

 

A, B = map(int, input().split())
if A>=1 and A<=10000 and B>=1 and B<=10000:
    print(A+B)
    print(A-B)
    print(A*B)
    print(A//B)
    print(A%B)