-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCalc.py
More file actions
86 lines (78 loc) · 2.77 KB
/
SimpleCalc.py
File metadata and controls
86 lines (78 loc) · 2.77 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import math
#SIMPLE CALCULATOR
#defining fuctions
def add(a,b):
print("\nthe sum is ",a+b,"\n")
def sub(a,b):
print("\nthe difference is ",a-b,"\n")
def mul(a,b):
print("\nthe product is ",a*b,"\n")
def div(a,b):
try :
c=a/b
print("\nthe result is ",c,"\n")
except:
print("\nZeroDivisionError\n")
#giving choices to the user
print("===========================================================")
print("SIMPLE CALCULATOR")
print("===========================================================")
print("\n")
print("OPERATIONS")
print(""" 1. Addition
2.Subtraction
3.Multiplication
4.Division
5.Square root of number
6. exponent (x^y)
7.Exit\n""")
print("===========================================================")
#get choice from the user
while True:
ch=int(input("enter choice(1-7):"))
print("\n")
if ch not in (1,2,3,4,5,6,7):
print("invalid choice , pls choose choice(1-7)")
if ch==1:
print("===========================================================")
a=int(input("enter number 1:"))
b=int(input("enter number 2:"))
add(a,b)
print("===========================================================")
elif ch==2:
print("===========================================================")
a=int(input("enter number 1:"))
b=int(input("enter number 2:"))
sub(a,b)
print("===========================================================")
elif ch==3:
print("===========================================================")
a=int(input("enter number 1:"))
b=int(input("enter number 2:"))
mul(a,b)
print("===========================================================")
elif ch==4:
print("===========================================================")
a=int(input("enter number 1:"))
b=int(input("enter number 2:"))
div(a,b)
print("===========================================================")
elif ch==5:
print("===========================================================")
a=int(input("enter number 1:"))
b=math.sqrt(a)
print("\nthe square root of",a," is ",b,"\n")
print("===========================================================")
elif ch==6:
print("===========================================================")
a=int(input("enter num 1:"))
b=int(input("enter num 2:"))
c=pow(a,b)
print(" the result is ",c,"\n")
print("===========================================================")
elif ch==7:
print("""===========================================================
Thank you for using Calculator
Have a great day!
===========================================================""")
break