티스토리 뷰
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
31
32
33
34
35
36
37
38
39
40
41
42
|
class Calculator:
num1 : int
num2 : int
opcode : str
@property
def num1(self) -> int: return self._num1
@num1.setter
def num1(self, num1): self._num1 = num1
@property
def num2(self) -> int: return self._num2
@num2.setter
def num2(self, num2): self._num2 = num2
@property
def opcode(self) -> int: return self._opcode
@opcode.setter
def opcode(self, opcode): self._opcode = opcode
def add(this): return this.num1 + this.num2
def subtract(this): return this.num1 - this.num2
def multiply(this): return this.num1 * this.num2
def divide(this): return this.num1 / this.num2
def calculate(this):
if this.opcode == '+':
result = add(this)
if this.opcode == '-':
result = subtract(this)
if this.opcode == '*':
result = multiply(this)
if this.opcode == '/':
result = divide(this)
return result
if __name__ == '__main__':
this = Calculator()
this.num1 = int(input('첫번째 수 \n'))
this.opcode = input('연산자 \n')
this.num2 = int(input('두번째 수 \n'))
result = calculate(this)
print(f'{this.num1} {this.opcode} {this.num2} = {result}')
|
cs |
'5. 파이썬' 카테고리의 다른 글
[파이썬 객체지향] 주소록 예제 (0) | 2020.05.09 |
---|---|
[텐서플로] 계산기 예제 (0) | 2020.05.09 |
SpamMail.py (0) | 2020.05.09 |
Sklearn Iris_3D_.py (0) | 2020.05.09 |
Tensorflow-1 Perceptron_Iris_.py (0) | 2020.05.09 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- JUnit
- Python
- React
- SpringBoot
- springMVC
- Algorithm
- Java
- intellij
- docker
- Eclipse
- mariadb
- Mlearn
- AWS
- nodejs
- KAFKA
- maven
- terms
- COLAB
- Django
- JPA
- FLASK
- database
- vscode
- SQLAlchemy
- tensorflow
- ERD
- Oracle
- jQuery
- Mongo
- Git
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함