Skip to content

Commit 1f87a24

Browse files
authored
Merge pull request DeepNinja07x#94 from ShreyaDayma-cse/master
Create Calculator.py
2 parents 56795d9 + b5b97eb commit 1f87a24

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

Basic Scripts/Calculator.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import math as m
2+
class calculator:
3+
def inp(self):
4+
self.a=int(input("Enter the first number:"))
5+
self.b=int(input("Enter the second number:"))
6+
print("The numbers are:",self.a," ",self.b)
7+
def add(self):
8+
return self.a+self.b
9+
def diff(self):
10+
return self.a-self.b
11+
def mul(self):
12+
return self.a*self.b
13+
def div(self):
14+
return self.a/self.b
15+
def cosine(self):
16+
return( m.cos(self.a)), (m.cos(self.b))
17+
def sine(self):
18+
return( m.sin(self.a)), (m.sin(self.b))
19+
def square(self):
20+
return(m.sqrt(self.a)),(m.sqrt(self.b))
21+
def cube(self):
22+
return (self.a**(1/3)),(self.b**(1/3))
23+
24+
25+
ob=calculator()
26+
c=1
27+
while c!=9:
28+
print(''' Enter 1 for sum
29+
2 for Difference
30+
3 for Multiplication
31+
4 for Division
32+
5 for cosine
33+
6 for sine
34+
7 for square root
35+
8 for cube root
36+
9 to exit:''')
37+
c=int(input("Enter the operation to be performed:"))
38+
if c==1:
39+
ob.inp()
40+
print("Sum=",ob.add(),"\n")
41+
elif c==2:
42+
ob.inp()
43+
print("Difference=",ob.diff(),"\n")
44+
elif c==3:
45+
ob.inp()
46+
print("Multiplication=",ob.mul(),"\n")
47+
elif c==4:
48+
ob.inp()
49+
print("Division=",ob.div(),"\n")
50+
elif c==5:
51+
ob.inp()
52+
print("Cosine values=",ob.cosine(),"\n")
53+
elif c==6:
54+
ob.inp()
55+
print("Sine values=",ob.sine(),"\n")
56+
elif c==7:
57+
ob.inp()
58+
print("Square roots=",ob.square(),"\n")
59+
elif c==8:
60+
ob.inp()
61+
print("Cube roots=",ob.cube(),"\n")
62+
else:
63+
print("Invalid")
64+

0 commit comments

Comments
 (0)