-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
52 lines (42 loc) · 1.21 KB
/
calculator.py
File metadata and controls
52 lines (42 loc) · 1.21 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
# calculator
# multiplication
def multi(x, y):
z = x * y
return z
# addition
def add(x, y):
z = x + y
return z
# subtraction
def sub(x, y):
z = x - y
return z
# division
def div(x, y):
z = x / y
return z
while True:
print("enter two numbers to perform arithmetic operation")
try:
a = int(input(" enter first number: "))
b = int(input(" enter second number: "))
print("The operations list ('x' -multi, '+' - add, '-' - subs, '/' - div)")
op = input(" enter the operation you want to perform: ")
if (op == 'x'):
c = multi(a, b)
elif (op == '+'):
c = add(a, b)
elif (op == '-'):
c = sub(a, b)
elif (op == '/'):
c = div(a, b)
else:
c = "err" # since not working of any of the above conditions will leave c without any value and that might result in an error
print(" enter a valid operation")
print(" Your result is : ", c)
run = input('To use calculator again enter 1 else enter any other key:')
if run != '1':
print('Bye!')
break
except:
print(" you entered an upsupported character")