-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculator.py
36 lines (35 loc) · 961 Bytes
/
calculator.py
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
exit=0
def add_ (x,y):
print("\nadd of",x,"+",y,"=", x+y)
def sub_ (x,y):
print("\nsub of",x,"-",y,"=", x-y)
def mul_ (x,y):
print("\nmull of",x,"*",y,"=", x*y)
def div_ (x,y):
if y!=0:
print("\ndiv of",x,"/",y,"=", x/y)
else :
print("not defined")
def squ_ (x,y):
print("\nmull of",x,"*",y,"=", x**y)
while exit==0:
print(" \n ================================= \n ======= simple calculator ======= \n ================================= \n \n")
fun=int(input("choose a function \n 1 : add \n 2 : sub \n 3 : mul \n 4 : div \n 5 : squar \n 0 : exit \n"))
if fun==0:
break
x=int(input("enter 1st number"))
y=int(input("enter 2nd number"))
if fun==1:
add_(x,y)
elif fun==2:
sub_(x,y)
elif fun==3:
mul_(x,y)
elif fun==4:
div_(x,y)
elif fun==5:
squ_(x,y)
elif fun==0:
break
else :
print("select a valid function")