-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_d07_class01.py
More file actions
63 lines (43 loc) · 1.03 KB
/
Copy pathpython_d07_class01.py
File metadata and controls
63 lines (43 loc) · 1.03 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
print('안녕하세요')
a = [3, 5, 7]
print('킹' + 'ace')
#### 예외 처리 ####
try:
a + 2
except (TypeError, IndexError) :
print('미안미안')
try:
a[2] / 0
except ZeroDivisionError as msg:
print(msg)
print('안녕하숑')
print('*'*30)
#### 모듈 분리(계산기) ####
## 초간단 계산기
def Add(x, y):
return x+y
def Sub(x, y):
return x-y
def Mul(x, y):
return x*y
def Div(x, y):
return x//y
while True:
print(' ** 간단 계산기 ** ')
print(' ===> [종료 : 0 ]')
n1 = int(input(' 첫 번째 수 : '))
if n1 == 0:
break
op = input(' [ +, - * / ] : ')
n2 = int(input(' 두 번째 수 : '))
if op == '+':
res = Add(n1, n2)
elif op == '-':
res = Sub(n1, n2)
elif op == '*':
res = Mul(n1, n2)
elif op == '/':
res = Div(n1, n2)
else:
print(op, '없는 연산입니다.')
print(' {} {} {} = {}'.format(n1, op, n2, res))