-
Notifications
You must be signed in to change notification settings - Fork 42
/
simple_calculator_in_loop.py
47 lines (46 loc) · 1.33 KB
/
simple_calculator_in_loop.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
37
38
39
40
41
42
43
44
45
46
47
def simc():
def add(a,b):
z=a+b
print("Sum is %d" % z)
def sub(a,b):
return a-b
def mul(a,b):
return a*b
def div(a,b):
return a/b
def rem(a,b):
return a%b
print("Simple Calculator")
while(1):
print("1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Remainder\n6.Exit")
ch = int(input("Enter your choice: "))
if (ch == 6):
print("Thank you and Exiting")
break
else:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if(ch==1):
add(a,b)
elif (ch==2):
z=sub(a,b)
print("Difference is %d"%z)
elif(ch==3):
z=mul(a,b)
print("Product is %d"%z)
elif (ch==4):
z=div(a,b)
print("Qoutient is %f"%z)
elif (ch==5):
z=rem(a,b)
print("Remainder is %d"%z)
else:
print("Invalid input!")
ch=input("Continue? (y/n): ")
if(ch=="y"):
continue
elif(ch=="n"):
break
else:
print("Invalid input!\nExiting.")
break