본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 22

반응형

Q>

사용자에게 x와 y를 입력받아 사칙연산을 하는 계산기 클래스를 작성하시오.


A>

class Calc:
def add(self, x, y):
print('덧셈 결과 값')
return x + y
def sub(self, x, y):
print('뺄셈 결과 값')
return x - y
def mul(self, x, y):
print('곱하기 결과 값')
return x * y
def div(self, x, y):
print('나눗셈 결과 값')
return x / y

num = input('x와 y를 입력하세요 : ')
num_list = list(num.split())

calc = Calc()
print(calc.add(int(num_list[0]), int(num_list[1])))
print(calc.sub(int(num_list[0]), int(num_list[1])))
print(calc.mul(int(num_list[0]), int(num_list[1])))
print(calc.div(int(num_list[0]), int(num_list[1])))


O>

x와 y를 입력하세요 : 2 3

덧셈 결과 값

5

뺄셈 결과 값

-1

곱하기 결과 값

6

나눗셈 결과 값

0.6666666666666666


Process finished with exit code 0

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 24  (0) 2019.04.13
Python Learn the basics Quiz 23  (0) 2019.04.08
Python Learn the basics Quiz 21  (0) 2019.03.30
Python Learn the basics Quiz 20  (0) 2019.03.28
Python Learn the basics Quiz 19  (0) 2019.03.27